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 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]);

View file

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