Fix to feed discovery (#1134)

* Fixes to debounce

* Less aggressive debounce
zio/stable
Paul Frazee 2023-08-08 11:56:34 -07:00 committed by GitHub
parent 72e459f3e2
commit e51dbefd0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -28,14 +28,14 @@ export const DiscoverFeedsScreen = withAuthRequired(
const [isInputFocused, setIsInputFocused] = React.useState<boolean>(false)
const [query, setQuery] = React.useState<string>('')
const debouncedSearchFeeds = React.useMemo(
() => debounce(() => feeds.search(query), 200), // debouce for 200 ms
[feeds, query],
() => debounce(query => feeds.search(query), 500), // debounce for 500ms
[feeds],
)
const onChangeQuery = React.useCallback(
(text: string) => {
setQuery(text)
if (text.length > 1) {
debouncedSearchFeeds()
debouncedSearchFeeds(text)
} else {
feeds.refresh()
}
@ -52,8 +52,9 @@ export const DiscoverFeedsScreen = withAuthRequired(
feeds.refresh()
}, [feeds])
const onSubmitQuery = React.useCallback(() => {
feeds.search(query)
}, [feeds, query])
debouncedSearchFeeds(query)
debouncedSearchFeeds.flush()
}, [debouncedSearchFeeds, query])
useFocusEffect(
React.useCallback(() => {