Skip to content

Commit

Permalink
Delay search url updating to not add lots of half written queries
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed May 16, 2024
1 parent a8c8e47 commit 532d067
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions frontend/src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ const SearchInput = () => {
}, [routerQuery])

const debouncedSubmit = useRef(debounce(value => updateContextQuery(value), 100))
const debouncedUpdateUrl = useRef(debounce(value => {
const path = value ? `/search?q=${encodeURIComponent(value)}` : '/'
replace(path, undefined, { shallow: true })
}, 1000))

const handleChange = (value: string) => {
debouncedSubmit.current.cancel()
debouncedUpdateUrl.current.cancel()
setInputQuery(value)
debouncedSubmit.current(value)
const path = value ? `/search?q=${encodeURIComponent(value)}` : '/'
replace(path, undefined, { shallow: true })
debouncedUpdateUrl.current(value)
}

return (
Expand Down

0 comments on commit 532d067

Please sign in to comment.