Skip to content

Commit

Permalink
Fix filter
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbarrdahl committed Feb 6, 2024
1 parent b0fe78e commit fb4e971
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/features/filter/hooks/useFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const initialFilter: Filter = {
limit: config.pageSize,
cursor: 0,
seed: 0,
search: null,
search: "",
};

export const sortLabels = {
Expand Down Expand Up @@ -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]);
}
2 changes: 1 addition & 1 deletion src/features/filter/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof SortEnum>;
Expand Down

0 comments on commit fb4e971

Please sign in to comment.