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