11import React from 'react'
2-
3- import throttle from 'lodash.throttle'
42import { getBlockParentPage , getBlockTitle } from '@texonom/nutils'
53
64import { NotionContextConsumer , NotionContextProvider } from '../context'
@@ -12,6 +10,15 @@ import { PageTitle } from './page-title'
1210import type { SearchParams , SearchResults , APIError } from '@texonom/ntypes'
1311// TODO: modal.default.setAppElement('.notion-viewport')
1412
13+ // simple debounce utility so we only search after the user stops typing
14+ const debounce = ( func : ( ...args : any [ ] ) => void , wait : number ) => {
15+ let timeout : ReturnType < typeof setTimeout > | undefined
16+ return ( ...args : any [ ] ) => {
17+ if ( timeout ) clearTimeout ( timeout )
18+ timeout = setTimeout ( ( ) => func ( ...args ) , wait )
19+ }
20+ }
21+
1522export class SearchDialog extends React . Component < {
1623 isOpen : boolean
1724 rootBlockId : string
@@ -34,7 +41,8 @@ export class SearchDialog extends React.Component<{
3441 _search : any
3542
3643 componentDidMount ( ) {
37- this . _search = throttle ( this . _searchImpl . bind ( this ) , 1000 )
44+ // debounce search calls so the expensive query only runs after typing stops
45+ this . _search = debounce ( this . _searchImpl . bind ( this ) , 500 )
3846 this . _warmupSearch ( )
3947 }
4048
@@ -66,7 +74,7 @@ export class SearchDialog extends React.Component<{
6674 placeholder = 'Search'
6775 value = { query }
6876 ref = { this . _inputRef }
69- onChange = { this . _onChangeQuery }
77+ onInput = { this . _onChangeQuery }
7078 />
7179
7280 { query && (
0 commit comments