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],
|
[updateUrl],
|
||||||
);
|
);
|
||||||
const getQueryParam = useCallback(
|
const getQueryParam = useCallback(
|
||||||
<T extends keyof QueryParams>(key: T): T | undefined => {
|
<T extends keyof QueryParams>(key: T): QueryParams[T] | undefined => {
|
||||||
return queryParams[key] as T;
|
return queryParams[key] as QueryParams[T];
|
||||||
},
|
},
|
||||||
[queryParams],
|
[queryParams],
|
||||||
);
|
);
|
||||||
|
@ -12,6 +12,7 @@ import { ChangeEvent, useEffect, useRef, useState } from "react";
|
|||||||
import {
|
import {
|
||||||
TBuildInitialParamProps,
|
TBuildInitialParamProps,
|
||||||
TBuildParamProps,
|
TBuildParamProps,
|
||||||
|
TFilterStringFields,
|
||||||
TParamItem,
|
TParamItem,
|
||||||
} from "@/types/search.types";
|
} from "@/types/search.types";
|
||||||
|
|
||||||
@ -23,13 +24,11 @@ const buildOrParams = <T>({ params, searchText }: TBuildParamProps<T>) => ({
|
|||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
const buildILikeParams = <T>({ params, searchText }: TBuildParamProps<T>) =>
|
const buildILikeParams = <T>({ params, searchText }: TBuildParamProps<T>) =>
|
||||||
params?.reduce(
|
params?.reduce((acc, field) => {
|
||||||
(acc, field) => ({
|
acc[field] = { contains: searchText };
|
||||||
...acc,
|
|
||||||
[field]: { contains: searchText },
|
return acc;
|
||||||
}),
|
}, {} as Record<TFilterStringFields<T>, unknown>);
|
||||||
{},
|
|
||||||
);
|
|
||||||
const buildEqInitialParams = <T>({
|
const buildEqInitialParams = <T>({
|
||||||
initialParams,
|
initialParams,
|
||||||
}: TBuildInitialParamProps<T>) =>
|
}: TBuildInitialParamProps<T>) =>
|
||||||
@ -75,11 +74,15 @@ export const useSearch = <T>({
|
|||||||
}, [searchText]);
|
}, [searchText]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (queryParamKey && queryParamValue !== searchText) {
|
if (
|
||||||
setSearchText(queryParamValue || "");
|
queryParamKey &&
|
||||||
|
queryParamValue !== searchText &&
|
||||||
|
queryParamValue !== undefined
|
||||||
|
) {
|
||||||
|
setSearchText(queryParamValue.toString() || "");
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [queryParamValue]);
|
}, [queryParamValue, queryParamKey]);
|
||||||
|
|
||||||
const onSearch = debounce(
|
const onSearch = debounce(
|
||||||
async (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string) => {
|
async (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user