@@ -66,6 +66,17 @@ const QuestionList: React.FC = () => {
66
66
) ;
67
67
} ;
68
68
69
+ const updateQuestionList = ( ) => {
70
+ getQuestionList (
71
+ page + 1 , // convert from 0-based indexing
72
+ rowsPerPage ,
73
+ searchFilter ,
74
+ complexityFilter ,
75
+ categoryFilter ,
76
+ dispatch
77
+ ) ;
78
+ } ;
79
+
69
80
// For handling edit / delete menu
70
81
const [ targetQuestion , setTargetQuestion ] = useState < string | null > ( null ) ;
71
82
const [ menuAnchor , setMenuAnchor ] = useState < HTMLElement | null > ( null ) ;
@@ -106,25 +117,11 @@ const QuestionList: React.FC = () => {
106
117
107
118
toast . success ( SUCCESS_QUESTION_DELETE ) ;
108
119
getQuestionCategories ( dispatch ) ;
109
- getQuestionList (
110
- page + 1 , // convert from 0-based indexing
111
- rowsPerPage ,
112
- searchFilter ,
113
- complexityFilter ,
114
- categoryFilter ,
115
- dispatch
116
- ) ;
117
- } ;
118
-
119
- const updateQuestionList = ( ) => {
120
- getQuestionList (
121
- page + 1 , // convert from 0-based indexing
122
- rowsPerPage ,
123
- searchFilter ,
124
- complexityFilter ,
125
- categoryFilter ,
126
- dispatch
127
- ) ;
120
+ if ( state . questionCount % rowsPerPage !== 1 || page === 0 ) {
121
+ updateQuestionList ( ) ;
122
+ } else {
123
+ setPage ( page - 1 ) ;
124
+ }
128
125
} ;
129
126
130
127
useEffect ( ( ) => {
@@ -137,8 +134,10 @@ const QuestionList: React.FC = () => {
137
134
} else {
138
135
updateQuestionList ( ) ;
139
136
}
137
+ // eslint-disable-next-line react-hooks/exhaustive-deps
140
138
} , [ searchFilter , complexityFilter , categoryFilter ] ) ;
141
139
140
+ // eslint-disable-next-line react-hooks/exhaustive-deps
142
141
useEffect ( ( ) => updateQuestionList ( ) , [ page ] ) ;
143
142
144
143
// Check if the user is admin
0 commit comments