@@ -6,6 +6,7 @@ import _ from 'lodash'
6
6
import ee from 'browser/main/lib/eventEmitter'
7
7
import NewNoteButton from 'browser/main/NewNoteButton'
8
8
import i18n from 'browser/lib/i18n'
9
+ import debounce from 'lodash/debounce'
9
10
10
11
class TopBar extends React . Component {
11
12
constructor ( props ) {
@@ -25,6 +26,10 @@ class TopBar extends React.Component {
25
26
}
26
27
27
28
this . codeInitHandler = this . handleCodeInit . bind ( this )
29
+
30
+ this . updateKeyword = debounce ( this . updateKeyword , 1000 / 60 , {
31
+ maxWait : 1000 / 8
32
+ } )
28
33
}
29
34
30
35
componentDidMount ( ) {
@@ -94,7 +99,6 @@ class TopBar extends React.Component {
94
99
}
95
100
96
101
handleKeyUp ( e ) {
97
- const { router } = this . context
98
102
// reset states
99
103
this . setState ( {
100
104
isConfirmTranslation : false
@@ -106,21 +110,21 @@ class TopBar extends React.Component {
106
110
isConfirmTranslation : true
107
111
} )
108
112
const keyword = this . refs . searchInput . value
109
- router . push ( `/searched/${ encodeURIComponent ( keyword ) } ` )
110
- this . setState ( {
111
- search : keyword
112
- } )
113
+ this . updateKeyword ( keyword )
113
114
}
114
115
}
115
116
116
117
handleSearchChange ( e ) {
117
- const { router } = this . context
118
- const keyword = this . refs . searchInput . value
119
118
if ( this . state . isAlphabet || this . state . isConfirmTranslation ) {
120
- router . push ( `/searched/${ encodeURIComponent ( keyword ) } ` )
119
+ const keyword = this . refs . searchInput . value
120
+ this . updateKeyword ( keyword )
121
121
} else {
122
122
e . preventDefault ( )
123
123
}
124
+ }
125
+
126
+ updateKeyword ( keyword ) {
127
+ this . context . router . push ( `/searched/${ encodeURIComponent ( keyword ) } ` )
124
128
this . setState ( {
125
129
search : keyword
126
130
} )
0 commit comments