Skip to content
Snippets Groups Projects
Verified Commit e00b7c94 authored by Dorian Koch's avatar Dorian Koch
Browse files

Fix search misbehaving, closes #53

parent d5537c46
No related branches found
No related tags found
No related merge requests found
Pipeline #6300 passed
...@@ -291,8 +291,8 @@ function Search({ className }: { className?: string }) { ...@@ -291,8 +291,8 @@ function Search({ className }: { className?: string }) {
e.preventDefault(); e.preventDefault();
let form = e.currentTarget; let form = e.currentTarget;
let query = form.query.value; let query = form.query.value;
if (query === "") router.push("/search"); const newPath = query === "" ? "/search" : "/search?q=" + encodeURIComponent(query);
router.push("/search?q=" + encodeURIComponent(query)); if (router.pathname !== newPath) router.push(newPath);
}; };
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setQuery(e.target.value); setQuery(e.target.value);
......
...@@ -62,7 +62,9 @@ export default function Search() { ...@@ -62,7 +62,9 @@ export default function Search() {
// TODO: this code needs more cleanup, variable names are not very descriptive // TODO: this code needs more cleanup, variable names are not very descriptive
useEffect(() => { useEffect(() => {
setQuery(params.get("q")); if (params.has("q")) setQuery(params.get("q"));
else if (query !== undefined && query !== null && query.length > 0) setQuery("");
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [params]); }, [params]);
const updateSearchResults = () => { const updateSearchResults = () => {
...@@ -91,7 +93,7 @@ export default function Search() { ...@@ -91,7 +93,7 @@ export default function Search() {
}; };
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(updateSearchResults, [query, api, router]); useEffect(updateSearchResults, [query, api]);
const [updateQueryDeferred, updateQueryNow] = useDebounce(() => { const [updateQueryDeferred, updateQueryNow] = useDebounce(() => {
setQuery(workingQuery.current); setQuery(workingQuery.current);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment