Skip to content

Commit

Permalink
fix: Fix sorting on mobile (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
soniaklimas committed Feb 3, 2025
1 parent 869f37c commit adc3129
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions apps/storefront/src/app/[locale]/(main)/search/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,16 @@ export const handleFiltersFormSubmit = async (
});

passThroughParams.forEach((param) => {
const paramsValue = searchParams[param];
const formValue = formData.get(param) as string;
const value = formValue ?? searchParams[param];

// Sorting can be changed either independently (on desktop)
// or together with filters (on mobile)
// that is why it needs some custom logic
if (param === "sortBy") {
const value = formValue ?? paramsValue;

if (value !== DEFAULT_SORT_BY) {
params.set(param, value);
} else {
params.delete(param);
}
}

if (searchParams[param]) {
params.set(param, searchParams[param]);
if (param === "sortBy" && value === DEFAULT_SORT_BY) {
params.delete(param);
} else if (value) {
params.set(param, value);
}
});

Expand Down

0 comments on commit adc3129

Please sign in to comment.