@@ -34,6 +34,7 @@ import {
34
34
StatusOption ,
35
35
BaseOption ,
36
36
} from "./options"
37
+ import debounce from "just-debounce-it"
37
38
38
39
export type FilterValues = {
39
40
owner ?: string // User["username"]
@@ -64,9 +65,15 @@ export const useFilter = ({
64
65
}
65
66
}
66
67
68
+ const debounceUpdate = debounce (
69
+ ( values : string | FilterValues ) => update ( values ) ,
70
+ 500 ,
71
+ )
72
+
67
73
return {
68
74
query,
69
75
update,
76
+ debounceUpdate,
70
77
values,
71
78
}
72
79
}
@@ -160,61 +167,54 @@ export const Filter = ({
160
167
161
168
return (
162
169
< Box display = "flex" sx = { { gap : 1 , mb : 2 } } >
163
- < Box
164
- component = "form"
165
- sx = { { width : "100%" } }
166
- onSubmit = { ( e ) => {
167
- e . preventDefault ( )
168
- const formData = new FormData ( e . currentTarget )
169
- const query = formData . get ( "query" ) as string
170
- filter . update ( query )
171
- } }
172
- >
173
- < TextField
174
- fullWidth
175
- error = { shouldDisplayError }
176
- helperText = {
177
- shouldDisplayError ? getValidationErrorMessage ( error ) : undefined
178
- }
179
- size = "small"
180
- InputProps = { {
181
- name : "query" ,
182
- placeholder : "Search..." ,
183
- value : searchQuery ,
184
- onChange : ( e ) => setSearchQuery ( e . target . value ) ,
185
- sx : {
186
- borderRadius : "6px" ,
187
- "& input::placeholder" : {
188
- color : ( theme ) => theme . palette . text . secondary ,
189
- } ,
170
+ < TextField
171
+ fullWidth
172
+ error = { shouldDisplayError }
173
+ helperText = {
174
+ shouldDisplayError ? getValidationErrorMessage ( error ) : undefined
175
+ }
176
+ size = "small"
177
+ InputProps = { {
178
+ name : "query" ,
179
+ placeholder : "Search..." ,
180
+ value : searchQuery ,
181
+ onChange : ( e ) => {
182
+ setSearchQuery ( e . target . value )
183
+ filter . debounceUpdate ( e . target . value )
184
+ } ,
185
+ sx : {
186
+ borderRadius : "6px" ,
187
+ "& input::placeholder" : {
188
+ color : ( theme ) => theme . palette . text . secondary ,
190
189
} ,
191
- startAdornment : (
192
- < InputAdornment position = "start" >
193
- < SearchOutlined
194
- sx = { {
195
- fontSize : 14 ,
196
- color : ( theme ) => theme . palette . text . secondary ,
190
+ } ,
191
+ startAdornment : (
192
+ < InputAdornment position = "start" >
193
+ < SearchOutlined
194
+ sx = { {
195
+ fontSize : 14 ,
196
+ color : ( theme ) => theme . palette . text . secondary ,
197
+ } }
198
+ />
199
+ </ InputAdornment >
200
+ ) ,
201
+ endAdornment : hasFilterQuery && (
202
+ < InputAdornment position = "end" >
203
+ < Tooltip title = "Clear filter" >
204
+ < IconButton
205
+ size = "small"
206
+ onClick = { ( ) => {
207
+ filter . update ( "" )
197
208
} }
198
- />
199
- </ InputAdornment >
200
- ) ,
201
- endAdornment : hasFilterQuery && (
202
- < InputAdornment position = "end" >
203
- < Tooltip title = "Clear filter" >
204
- < IconButton
205
- size = "small"
206
- onClick = { ( ) => {
207
- filter . update ( "" )
208
- } }
209
- >
210
- < CloseOutlined sx = { { fontSize : 14 } } />
211
- </ IconButton >
212
- </ Tooltip >
213
- </ InputAdornment >
214
- ) ,
215
- } }
216
- />
217
- </ Box >
209
+ >
210
+ < CloseOutlined sx = { { fontSize : 14 } } />
211
+ </ IconButton >
212
+ </ Tooltip >
213
+ </ InputAdornment >
214
+ ) ,
215
+ } }
216
+ />
217
+
218
218
{ autocomplete . users && < OwnerFilter autocomplete = { autocomplete . users } /> }
219
219
< TemplatesFilter autocomplete = { autocomplete . templates } />
220
220
< StatusFilter autocomplete = { autocomplete . status } />
0 commit comments