mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: apply feedback
This commit is contained in:
parent
bcca90b979
commit
7ddfdfc75a
@ -51,8 +51,8 @@ export const useQueryParam = () => {
|
||||
[updateUrl],
|
||||
);
|
||||
const getQueryParam = useCallback(
|
||||
<T extends keyof QueryParams>(key: T): T | undefined => {
|
||||
return queryParams[key] as T;
|
||||
<T extends keyof QueryParams>(key: T): QueryParams[T] | undefined => {
|
||||
return queryParams[key] as QueryParams[T];
|
||||
},
|
||||
[queryParams],
|
||||
);
|
||||
|
@ -12,6 +12,7 @@ import { ChangeEvent, useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
TBuildInitialParamProps,
|
||||
TBuildParamProps,
|
||||
TFilterStringFields,
|
||||
TParamItem,
|
||||
} from "@/types/search.types";
|
||||
|
||||
@ -23,13 +24,11 @@ const buildOrParams = <T>({ params, searchText }: TBuildParamProps<T>) => ({
|
||||
})),
|
||||
});
|
||||
const buildILikeParams = <T>({ params, searchText }: TBuildParamProps<T>) =>
|
||||
params?.reduce(
|
||||
(acc, field) => ({
|
||||
...acc,
|
||||
[field]: { contains: searchText },
|
||||
}),
|
||||
{},
|
||||
);
|
||||
params?.reduce((acc, field) => {
|
||||
acc[field] = { contains: searchText };
|
||||
|
||||
return acc;
|
||||
}, {} as Record<TFilterStringFields<T>, unknown>);
|
||||
const buildEqInitialParams = <T>({
|
||||
initialParams,
|
||||
}: TBuildInitialParamProps<T>) =>
|
||||
@ -75,11 +74,15 @@ export const useSearch = <T>({
|
||||
}, [searchText]);
|
||||
|
||||
useEffect(() => {
|
||||
if (queryParamKey && queryParamValue !== searchText) {
|
||||
setSearchText(queryParamValue || "");
|
||||
if (
|
||||
queryParamKey &&
|
||||
queryParamValue !== searchText &&
|
||||
queryParamValue !== undefined
|
||||
) {
|
||||
setSearchText(queryParamValue.toString() || "");
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [queryParamValue]);
|
||||
}, [queryParamValue, queryParamKey]);
|
||||
|
||||
const onSearch = debounce(
|
||||
async (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string) => {
|
||||
|
Loading…
Reference in New Issue
Block a user