From a29bb378901fd0e9465a208ee7ad1d364c5a7f71 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Mon, 26 May 2025 18:04:37 +0100 Subject: [PATCH] fix(frontend): enhance logic --- frontend/src/hooks/useQueryParam.ts | 2 +- frontend/src/hooks/useSearch.ts | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/frontend/src/hooks/useQueryParam.ts b/frontend/src/hooks/useQueryParam.ts index 0f027f7f..8445bf2d 100644 --- a/frontend/src/hooks/useQueryParam.ts +++ b/frontend/src/hooks/useQueryParam.ts @@ -28,7 +28,7 @@ export const useQueryParam = () => { } }); - await router.replace( + await router.push( { query: updatedQuery, }, diff --git a/frontend/src/hooks/useSearch.ts b/frontend/src/hooks/useSearch.ts index 9cb3e8ec..db19f827 100644 --- a/frontend/src/hooks/useSearch.ts +++ b/frontend/src/hooks/useSearch.ts @@ -67,23 +67,24 @@ export const useSearch = ({ queryParamValue?.toString() || "", ); + useEffect(() => { + if (queryParamValue) { + setSearchText(queryParamValue.toString() || ""); + } else { + if (searchText && ref.current) { + ref.current.value = ""; + } + setSearchText(""); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [queryParamValue]); + useEffect(() => { if (searchText && ref.current) { ref.current.value = searchText; } }, [searchText]); - useEffect(() => { - if ( - queryParamKey && - queryParamValue !== searchText && - queryParamValue !== undefined - ) { - setSearchText(queryParamValue.toString() || ""); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [queryParamValue, queryParamKey]); - const onSearch = debounce( async (e: ChangeEvent | string) => { const newSearchText = typeof e === "string" ? e : e.target.value;