fix(frontend): enhance logic

This commit is contained in:
yassinedorbozgithub 2025-05-26 18:04:37 +01:00
parent 7ddfdfc75a
commit a29bb37890
2 changed files with 13 additions and 12 deletions

View File

@ -28,7 +28,7 @@ export const useQueryParam = () => {
}
});
await router.replace(
await router.push(
{
query: updatedQuery,
},

View File

@ -67,23 +67,24 @@ export const useSearch = <T>({
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<HTMLInputElement | HTMLTextAreaElement> | string) => {
const newSearchText = typeof e === "string" ? e : e.target.value;