Просмотр исходного кода

Fix search functionality to allow repeated searches from any page

Co-authored-by: kouki-o <13145344+kouki-o@users.noreply.github.com>
copilot-swe-agent[bot] 2 месяцев назад
Родитель
Сommit
d31ce88dd1
1 измененных файлов с 3 добавлено и 1 удалено
  1. 3 1
      apps/app/src/states/search/keyword-manager.ts

+ 3 - 1
apps/app/src/states/search/keyword-manager.ts

@@ -66,7 +66,9 @@ export const useSetSearchKeyword = (
   return useCallback(
     (newKeyword: string) => {
       setKeyword((prevKeyword) => {
-        if (prevKeyword !== newKeyword) {
+        const isOnSearchPage = routerRef.current.pathname === pathname;
+        // Navigate if keyword changed OR if not currently on search page
+        if (prevKeyword !== newKeyword || !isOnSearchPage) {
           const newUrl = new URL(pathname, 'http://example.com');
           newUrl.searchParams.append('q', newKeyword);
           routerRef.current.push(`${newUrl.pathname}${newUrl.search}`, '');