Skip to content

Commit

Permalink
simplified year param
Browse files Browse the repository at this point in the history
  • Loading branch information
remko48 committed Oct 24, 2023
1 parent 8e5b789 commit 8c16738
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pwa/src/services/filtersToQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { generateYearsArray } from "../data/years";

export const filtersToQueryParams = (filters: any): string => {
const cleanedFilters = Object.fromEntries(
Object.entries(filters).filter(([key]) => !filterKeysToRemove.includes(key)),
Expand All @@ -20,6 +22,9 @@ export const filtersToQueryParams = (filters: any): string => {
};

export const filtersToUrlQueryParams = (filters: Record<string, any>): string => {
const today = new Date();
const currentYear = today.getFullYear();

const cleanedFilters = Object.fromEntries(
Object.entries(filters).filter(([key]) => !filterKeysToRemove.includes(key)),
);
Expand All @@ -32,6 +37,13 @@ export const filtersToUrlQueryParams = (filters: Record<string, any>): string =>
? value.map((v: string) => v.replace(/\s+/g, "_")).join(`&${key}[]=`)
: (value as string).replace(/\s+/g, "_");

if (key == "Publicatiedatum[after]") return;
if (key == "Publicatiedatum[before]")
return `year=${
generateYearsArray(currentYear - 1995).find((year: any) => {
return year.before === value;
})?.value
}`;
return `${Array.isArray(value) ? `${key}[]` : key}=${formattedValue}`;
})
.filter(Boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const FiltersTemplate: React.FC<FiltersTemplateProps> = ({ isLoading }) =
setValue(
"year",
generateYearsArray(currentYear - 1995).find((year: any) => {
return year.after === params.Publicatiedatum?.after && year.before === params.Publicatiedatum?.before;
return year.value === params.year;
}),
);

Expand Down

0 comments on commit 8c16738

Please sign in to comment.