Trim queries with whitespace (#2002)
* Disable rank sorting when query is empty * Trim query in handlers * Fix crash on empty query
This commit is contained in:
parent
f24f7b3089
commit
b9d94ccd83
2 changed files with 5 additions and 3 deletions
|
@ -14,6 +14,8 @@ export function useSortRedirects(
|
||||||
) {
|
) {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
|
|
||||||
|
const hasQuery = !!params.query?.trim();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const sortWithQuery = ProductListUrlSortField.rank;
|
const sortWithQuery = ProductListUrlSortField.rank;
|
||||||
const sortWithoutQuery =
|
const sortWithoutQuery =
|
||||||
|
@ -23,8 +25,8 @@ export function useSortRedirects(
|
||||||
navigate(
|
navigate(
|
||||||
productListUrl({
|
productListUrl({
|
||||||
...params,
|
...params,
|
||||||
asc: params.query ? false : params.asc,
|
asc: hasQuery ? false : params.asc,
|
||||||
sort: params.query ? sortWithQuery : sortWithoutQuery
|
sort: hasQuery ? sortWithQuery : sortWithoutQuery
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}, [params.query]);
|
}, [params.query]);
|
||||||
|
|
|
@ -62,7 +62,7 @@ function createFilterHandlers<
|
||||||
after: undefined,
|
after: undefined,
|
||||||
before: undefined,
|
before: undefined,
|
||||||
activeTab: undefined,
|
activeTab: undefined,
|
||||||
query
|
query: query?.trim()
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue