Skip to content

Commit 618cbf4

Browse files
Tony QiuTony Qiu
authored andcommitted
redirect user to latest search found in localstorage if empty search
1 parent 4c95eff commit 618cbf4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

frontend/src/hooks/useSearchState.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export function useSearchState() {
1919
// On initial mount, only sync if there's an actual search param
2020
if (searchParam) {
2121
setInputValue(searchParam);
22+
} else if (lastSearch && lastSearch.trim()) {
23+
// If URL is empty but we have a last search, redirect to it
24+
setInputValue(lastSearch);
25+
setSearchParams((prev) => {
26+
const nextParams = new URLSearchParams(prev);
27+
nextParams.set("search", lastSearch);
28+
return nextParams;
29+
});
2230
}
2331
} else {
2432
// On subsequent updates, always sync with URL

0 commit comments

Comments
 (0)