From 9b823af4f15583b2ba6632070450bd87e9d6309f Mon Sep 17 00:00:00 2001 From: Donkie Date: Tue, 24 Oct 2023 20:27:00 +0200 Subject: [PATCH] Fixed formatting in saveload.ts --- client/src/utils/saveload.ts | 38 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/client/src/utils/saveload.ts b/client/src/utils/saveload.ts index 4d20c6d..35d2dbe 100644 --- a/client/src/utils/saveload.ts +++ b/client/src/utils/saveload.ts @@ -15,9 +15,21 @@ export interface TableState { export function useInitialTableState(tableId: string): TableState { const [initialState] = React.useState(() => { - const savedSorters = hasHashProperty('sorters') ? getHashProperty('sorters') : isLocalStorageAvailable ? localStorage.getItem(`${tableId}-sorters`) : null; - const savedFilters = hasHashProperty('filters') ? getHashProperty('filters') : isLocalStorageAvailable ? localStorage.getItem(`${tableId}-filters`) : null; - const savedPagination = hasHashProperty('pagination') ? getHashProperty('pagination') : isLocalStorageAvailable ? localStorage.getItem(`${tableId}-pagination`) : null; + const savedSorters = hasHashProperty("sorters") + ? getHashProperty("sorters") + : isLocalStorageAvailable + ? localStorage.getItem(`${tableId}-sorters`) + : null; + const savedFilters = hasHashProperty("filters") + ? getHashProperty("filters") + : isLocalStorageAvailable + ? localStorage.getItem(`${tableId}-filters`) + : null; + const savedPagination = hasHashProperty("pagination") + ? getHashProperty("pagination") + : isLocalStorageAvailable + ? localStorage.getItem(`${tableId}-pagination`) + : null; const savedShowColumns = isLocalStorageAvailable ? localStorage.getItem(`${tableId}-showColumns`) : null; const sorters = savedSorters ? JSON.parse(savedSorters) : [{ field: "id", order: "asc" }]; @@ -37,20 +49,20 @@ export function useStoreInitialState(tableId: string, state: TableState) { } setURLHash(`sorters`, JSON.stringify(state.sorters)); } else { - localStorage.removeItem(`${tableId}-sorters`) - removeURLHash('sorters'); + localStorage.removeItem(`${tableId}-sorters`); + removeURLHash("sorters"); } }, [tableId, state.sorters]); React.useEffect(() => { - let filters = state.filters.filter(f => f.value.length != 0); + const filters = state.filters.filter((f) => f.value.length != 0); if (filters.length > 0) { if (isLocalStorageAvailable) { localStorage.setItem(`${tableId}-filters`, JSON.stringify(filters)); - setURLHash('filters', JSON.stringify(state.filters)); + setURLHash("filters", JSON.stringify(state.filters)); } } else { - localStorage.removeItem(`${tableId}-filters`) + localStorage.removeItem(`${tableId}-filters`); removeURLHash(`filters`); } }, [tableId, state.filters]); @@ -62,10 +74,9 @@ export function useStoreInitialState(tableId: string, state: TableState) { } setURLHash(`pagination`, JSON.stringify(state.pagination)); } else { - localStorage.removeItem(`${tableId}-pagination`) + localStorage.removeItem(`${tableId}-pagination`); removeURLHash(`pagination`); } - }, [tableId, state.pagination]); React.useEffect(() => { @@ -76,7 +87,6 @@ export function useStoreInitialState(tableId: string, state: TableState) { localStorage.setItem(`${tableId}-showColumns`, JSON.stringify(state.showColumns)); } } - }, [tableId, state.showColumns]); } @@ -98,7 +108,7 @@ export function useSavedState(id: string, defaultValue: T) { function setURLHash(Id: string, value: string) { const params = new URLSearchParams(window.location.hash.substring(1)); if (!params.has(Id)) { - params.append(Id, value) + params.append(Id, value); } params.set(Id, value); window.location.hash = params.toString(); @@ -106,7 +116,7 @@ function setURLHash(Id: string, value: string) { function removeURLHash(Id: string) { const params = new URLSearchParams(window.location.hash.substring(1)); if (params.has(Id)) { - params.delete(Id) + params.delete(Id); } window.location.hash = params.toString(); } @@ -119,4 +129,4 @@ function getHashProperty(Id: string) { function hasHashProperty(property: string): boolean { const hash = new URLSearchParams(window.location.hash.substring(1)); return hash.has(property); -} \ No newline at end of file +}