@@ -53,7 +53,7 @@ const QuestionList: React.FC = () => {
53
53
const [ searchFilter , setSearchFilter ] = useDebounce < string > ( "" , 1000 ) ;
54
54
const [ complexityFilter , setComplexityFilter ] = useDebounce < string [ ] > (
55
55
[ ] ,
56
- 1000 ,
56
+ 1000
57
57
) ;
58
58
const [ categoryFilter , setCategoryFilter ] = useDebounce < string [ ] > ( [ ] , 1000 ) ;
59
59
const [ selectedCategories , setSelectedCategories ] = useState < string [ ] > ( [ ] ) ;
@@ -72,7 +72,7 @@ const QuestionList: React.FC = () => {
72
72
const menuOpen = Boolean ( menuAnchor ) ;
73
73
const handleMenuOpen = (
74
74
event : React . MouseEvent < HTMLElement > ,
75
- questionId : string ,
75
+ questionId : string
76
76
) => {
77
77
setMenuAnchor ( event . currentTarget ) ;
78
78
setTargetQuestion ( questionId ) ;
@@ -112,24 +112,34 @@ const QuestionList: React.FC = () => {
112
112
searchFilter ,
113
113
complexityFilter ,
114
114
categoryFilter ,
115
- dispatch ,
115
+ dispatch
116
116
) ;
117
117
} ;
118
118
119
- useEffect ( ( ) => {
120
- getQuestionCategories ( dispatch ) ;
121
- } , [ ] ) ;
122
-
123
- useEffect ( ( ) => {
119
+ const updateQuestionList = ( ) => {
124
120
getQuestionList (
125
121
page + 1 , // convert from 0-based indexing
126
122
rowsPerPage ,
127
123
searchFilter ,
128
124
complexityFilter ,
129
125
categoryFilter ,
130
- dispatch ,
126
+ dispatch
131
127
) ;
132
- } , [ page , searchFilter , complexityFilter , categoryFilter ] ) ;
128
+ } ;
129
+
130
+ useEffect ( ( ) => {
131
+ getQuestionCategories ( dispatch ) ;
132
+ } , [ ] ) ;
133
+
134
+ useEffect ( ( ) => {
135
+ if ( page !== 0 ) {
136
+ setPage ( 0 ) ;
137
+ } else {
138
+ updateQuestionList ( ) ;
139
+ }
140
+ } , [ searchFilter , complexityFilter , categoryFilter ] ) ;
141
+
142
+ useEffect ( ( ) => updateQuestionList ( ) , [ page ] ) ;
133
143
134
144
// Check if the user is admin
135
145
const auth = useAuth ( ) ;
@@ -312,10 +322,10 @@ const QuestionList: React.FC = () => {
312
322
question . complexity === "Easy"
313
323
? "success.main"
314
324
: question . complexity === "Medium"
315
- ? "#D2C350"
316
- : question . complexity === "Hard"
317
- ? "error.main"
318
- : grey [ 500 ] ,
325
+ ? "#D2C350"
326
+ : question . complexity === "Hard"
327
+ ? "error.main"
328
+ : grey [ 500 ] ,
319
329
} }
320
330
>
321
331
{ question . complexity }
0 commit comments