mirror of
https://github.com/Jellify-Music/App.git
synced 2026-01-21 10:21:19 -06:00
fix search debounce
This commit is contained in:
@@ -4,7 +4,7 @@ import { StackParamList } from "../../../components/types";
|
||||
import { usePlayerContext } from "../../../player/provider";
|
||||
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
|
||||
import { FlatList } from "react-native";
|
||||
import { SafeAreaView, useSafeAreaFrame } from "react-native-safe-area-context";
|
||||
import { useSafeAreaFrame } from "react-native-safe-area-context";
|
||||
|
||||
export default function Queue({ navigation }: { navigation: NativeStackNavigationProp<StackParamList>}): React.JSX.Element {
|
||||
|
||||
|
||||
@@ -23,16 +23,19 @@ export default function Search({
|
||||
queryFn: () => fetchSearchResults(searchString)
|
||||
})
|
||||
|
||||
const search = useCallback(
|
||||
debounce(() => {
|
||||
refetch();
|
||||
}, 750),
|
||||
[]
|
||||
);
|
||||
const search = (func : () => void, delay : number) => useCallback(() => {
|
||||
|
||||
let timeout : NodeJS.Timeout;
|
||||
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => func(), delay)
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleSearchStringUpdate = (value: string | undefined) => {
|
||||
setSearchString(value)
|
||||
search();
|
||||
search(refetch, 1000);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user