From fb4e97177b3e311881c830b769f3206ffa9b417c Mon Sep 17 00:00:00 2001 From: Carl Barrdahl Date: Tue, 6 Feb 2024 06:18:31 +0100 Subject: [PATCH] Fix filter --- src/features/filter/hooks/useFilter.ts | 9 +++++++-- src/features/filter/types/index.ts | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/features/filter/hooks/useFilter.ts b/src/features/filter/hooks/useFilter.ts index dc4918dd..882c1e8d 100644 --- a/src/features/filter/hooks/useFilter.ts +++ b/src/features/filter/hooks/useFilter.ts @@ -13,7 +13,7 @@ export const initialFilter: Filter = { limit: config.pageSize, cursor: 0, seed: 0, - search: null, + search: "", }; export const sortLabels = { @@ -68,7 +68,12 @@ export function useUpdateFilterFromRouter(type: FilterType) { // Update filter when router query changes useEffect(() => { if (JSON.stringify(filter) !== JSON.stringify(query)) { - setFilter(query); + setFilter({ + ...query, + limit: query.limit ? Number(query.limit) : initialFilter.limit, + cursor: query.cursor ? Number(query.cursor) : initialFilter.cursor, + seed: query.seed ? Number(query.seed) : initialFilter.seed, + }); } }, [query, setFilter]); } diff --git a/src/features/filter/types/index.ts b/src/features/filter/types/index.ts index 9bc9623b..fb29f265 100644 --- a/src/features/filter/types/index.ts +++ b/src/features/filter/types/index.ts @@ -11,7 +11,7 @@ export const FilterSchema = z.object({ seed: z.number().default(0), orderBy: SortEnum, sortOrder: SortOrderEnum, - search: z.string().nullish(), + search: z.string().default(""), }); export type Sort = z.infer;