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:
Michał Droń 2022-04-26 15:30:18 +02:00 committed by GitHub
parent f24f7b3089
commit b9d94ccd83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -14,6 +14,8 @@ export function useSortRedirects(
) {
const navigate = useNavigator();
const hasQuery = !!params.query?.trim();
useEffect(() => {
const sortWithQuery = ProductListUrlSortField.rank;
const sortWithoutQuery =
@ -23,8 +25,8 @@ export function useSortRedirects(
navigate(
productListUrl({
...params,
asc: params.query ? false : params.asc,
sort: params.query ? sortWithQuery : sortWithoutQuery
asc: hasQuery ? false : params.asc,
sort: hasQuery ? sortWithQuery : sortWithoutQuery
})
);
}, [params.query]);

View file

@ -62,7 +62,7 @@ function createFilterHandlers<
after: undefined,
before: undefined,
activeTab: undefined,
query
query: query?.trim()
})
);
};