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 Sep 23, 2024
1 parent 31a2e9c commit 301dfc7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions frontend/src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ 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 301dfc7

Please sign in to comment.