Skip to content

Commit 92f8a19

Browse files
author
Jeffrey-Xu
committed
fix: Resolve Practice page loading issue by fixing circular dependency
- Convert handler functions to useCallback to prevent circular dependency - Fix handleNext and handlePrevious being referenced before definition - This should resolve the blank Practice page issue on production
1 parent a120807 commit 92f8a19

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/pages/PracticePage.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ const PracticePage: React.FC = () => {
145145
const displayQuestions = recommendedQuestions.length > 0 ? recommendedQuestions : filteredQuestions;
146146
const currentQuestion = displayQuestions[currentQuestionIndex];
147147

148-
const handleAnswer = (answer: string, timeSpent: number) => {
148+
const handleAnswer = useCallback((answer: string, timeSpent: number) => {
149149
if (!currentQuestion) return;
150150

151151
const isCorrect = answer === currentQuestion.correct_answer;
152152
const questionDomain = categorizeQuestion(currentQuestion);
153153
updateQuestionProgress(currentQuestion.id, isCorrect, timeSpent, questionDomain);
154154
setShowExplanation(true);
155-
};
155+
}, [currentQuestion, updateQuestionProgress]);
156156

157-
const handleNext = () => {
157+
const handleNext = useCallback(() => {
158158
if (currentQuestionIndex < displayQuestions.length - 1) {
159159
setIsTransitioning(true);
160160
setTimeout(() => {
@@ -163,9 +163,9 @@ const PracticePage: React.FC = () => {
163163
setIsTransitioning(false);
164164
}, 150);
165165
}
166-
};
166+
}, [currentQuestionIndex, displayQuestions.length]);
167167

168-
const handlePrevious = () => {
168+
const handlePrevious = useCallback(() => {
169169
if (currentQuestionIndex > 0) {
170170
setIsTransitioning(true);
171171
setTimeout(() => {
@@ -174,28 +174,28 @@ const PracticePage: React.FC = () => {
174174
setIsTransitioning(false);
175175
}, 150);
176176
}
177-
};
177+
}, [currentQuestionIndex]);
178178

179-
const handleStartRecommendedSession = (questions: typeof filteredQuestions, sessionType: string) => {
179+
const handleStartRecommendedSession = useCallback((questions: typeof filteredQuestions, sessionType: string) => {
180180
setRecommendedQuestions(questions);
181181
setCurrentQuestionIndex(0);
182182
setShowExplanation(false);
183183
setShowRecommendations(false);
184-
};
184+
}, []);
185185

186-
const handleExitRecommendedSession = () => {
186+
const handleExitRecommendedSession = useCallback(() => {
187187
setRecommendedQuestions([]);
188188
setCurrentQuestionIndex(0);
189189
setShowExplanation(false);
190-
};
190+
}, []);
191191

192-
const handleStartFlashcards = () => {
192+
const handleStartFlashcards = useCallback(() => {
193193
setShowFlashcards(true);
194-
};
194+
}, []);
195195

196-
const handleExitFlashcards = () => {
196+
const handleExitFlashcards = useCallback(() => {
197197
setShowFlashcards(false);
198-
};
198+
}, []);
199199

200200
// Calculate question counts for filters
201201
const questionCounts = {

0 commit comments

Comments
 (0)