@@ -40,6 +40,8 @@ import { MultiSelect } from "@/components/ui/multiselect";
40
40
import { capitalizeWords } from "@/utils/string_utils" ;
41
41
import { topicsList } from "@/utils/constants" ;
42
42
43
+ const SEARCH_DEBOUNCE_TIMEOUT = 300 ;
44
+
43
45
const Cell = ( {
44
46
className,
45
47
children,
@@ -154,6 +156,16 @@ const ActionsCell: React.FC<ActionCellProps> = ({
154
156
) ;
155
157
} ;
156
158
159
+ function debounce < T extends ( ...args : any [ ] ) => void > ( func : T , timeout = 300 ) {
160
+ let timer : NodeJS . Timeout | undefined ;
161
+ return ( ...args : Parameters < T > ) => {
162
+ if ( timer ) clearTimeout ( timer ) ;
163
+ timer = setTimeout ( ( ) => {
164
+ func ( ...args ) ;
165
+ } , timeout ) ;
166
+ } ;
167
+ }
168
+
157
169
export function LeetcodeDashboardTable ( {
158
170
refreshKey,
159
171
setRefreshKey,
@@ -216,6 +228,10 @@ export function LeetcodeDashboardTable({
216
228
const [ isFilterOpen , setIsFilterOpen ] = React . useState < boolean > ( false ) ;
217
229
const [ isLoading , setIsLoading ] = React . useState < boolean > ( false ) ;
218
230
231
+ const debouncedSetSearchTitle = debounce ( ( title : string ) => {
232
+ setSearchTitle ( title ) ;
233
+ } , SEARCH_DEBOUNCE_TIMEOUT ) ;
234
+
219
235
const questionDifficulty = Object . values ( QuestionDifficulty ) . map ( ( q1 ) => {
220
236
return {
221
237
label : capitalizeWords ( q1 ) ,
@@ -265,7 +281,6 @@ export function LeetcodeDashboardTable({
265
281
] ;
266
282
267
283
useEffect ( ( ) => {
268
- setIsLoading ( true ) ;
269
284
getLeetcodeDashboardData (
270
285
pagination . pageIndex + 1 ,
271
286
pagination . pageSize ,
@@ -327,7 +342,9 @@ export function LeetcodeDashboardTable({
327
342
< Input
328
343
className = "w-[16rem] pl-10 !placeholder-primary-400"
329
344
placeholder = "Search Question Name"
330
- onChange = { ( e ) => setSearchTitle ( e . target . value ) }
345
+ onChange = { ( e ) => {
346
+ debouncedSetSearchTitle ( e . target . value ) ;
347
+ } }
331
348
/>
332
349
</ div >
333
350
< div className = "relative" >
@@ -390,7 +407,7 @@ export function LeetcodeDashboardTable({
390
407
) ) }
391
408
</ TableHeader >
392
409
< TableBody className = "bg-primary-900 text-primary-300 text-xs" >
393
- { table . getRowModel ( ) . rows ?. length ? (
410
+ { table . getRowModel ( ) . rows ?. length && ! isLoading ? (
394
411
table . getRowModel ( ) . rows . map ( ( row ) => (
395
412
< TableRow
396
413
key = { row . id }
0 commit comments