Skip to content

Commit 47f99e8

Browse files
author
Jeffrey-Xu
committed
fix: Clean up PracticePage.tsx - remove all duplicate declarations
- Removed duplicate displayQuestions and currentQuestion declarations - Removed duplicate handleAnswer, handleNext, handlePrevious functions - Removed duplicate handleStartRecommendedSession, handleExitRecommendedSession functions - Organized code structure with proper variable declaration order - Fixed all syntax errors and temporal dead zone issues - This should resolve all build errors
1 parent ec6e27d commit 47f99e8

File tree

1 file changed

+3
-57
lines changed

1 file changed

+3
-57
lines changed

src/pages/PracticePage.tsx

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const PracticePage: React.FC = () => {
4242
const [recommendedQuestions, setRecommendedQuestions] = useState<typeof questions>([]);
4343
const [isTransitioning, setIsTransitioning] = useState(false);
4444

45-
// Apply filters with progress data for bookmarks - MOVED UP
45+
// Apply filters with progress data for bookmarks
4646
const filteredQuestions = React.useMemo(() => {
4747
return questions.filter(question => {
4848
// Category filter
@@ -87,6 +87,7 @@ const PracticePage: React.FC = () => {
8787
const displayQuestions = recommendedQuestions.length > 0 ? recommendedQuestions : filteredQuestions;
8888
const currentQuestion = displayQuestions[currentQuestionIndex];
8989

90+
// Handler functions using useCallback
9091
const handleAnswer = useCallback((answer: string, timeSpent: number) => {
9192
if (!currentQuestion) return;
9293

@@ -139,6 +140,7 @@ const PracticePage: React.FC = () => {
139140
setShowFlashcards(false);
140141
}, []);
141142

143+
// Effects
142144
useEffect(() => {
143145
if (questions.length === 0 && !loading) {
144146
loadQuestions();
@@ -196,62 +198,6 @@ const PracticePage: React.FC = () => {
196198
window.addEventListener('keydown', handleKeyPress);
197199
return () => window.removeEventListener('keydown', handleKeyPress);
198200
}, [currentQuestionIndex, displayQuestions.length, handleNext, handlePrevious]);
199-
200-
// Determine which questions to display: recommended questions take priority over filtered questions
201-
const displayQuestions = recommendedQuestions.length > 0 ? recommendedQuestions : filteredQuestions;
202-
const currentQuestion = displayQuestions[currentQuestionIndex];
203-
204-
const handleAnswer = useCallback((answer: string, timeSpent: number) => {
205-
if (!currentQuestion) return;
206-
207-
const isCorrect = answer === currentQuestion.correct_answer;
208-
const questionDomain = categorizeQuestion(currentQuestion);
209-
updateQuestionProgress(currentQuestion.id, isCorrect, timeSpent, questionDomain);
210-
setShowExplanation(true);
211-
}, [currentQuestion, updateQuestionProgress]);
212-
213-
const handleNext = useCallback(() => {
214-
if (currentQuestionIndex < displayQuestions.length - 1) {
215-
setIsTransitioning(true);
216-
setTimeout(() => {
217-
setCurrentQuestionIndex(prev => prev + 1);
218-
setShowExplanation(false);
219-
setIsTransitioning(false);
220-
}, 150);
221-
}
222-
}, [currentQuestionIndex, displayQuestions.length]);
223-
224-
const handlePrevious = useCallback(() => {
225-
if (currentQuestionIndex > 0) {
226-
setIsTransitioning(true);
227-
setTimeout(() => {
228-
setCurrentQuestionIndex(prev => prev - 1);
229-
setShowExplanation(false);
230-
setIsTransitioning(false);
231-
}, 150);
232-
}
233-
}, [currentQuestionIndex]);
234-
235-
const handleStartRecommendedSession = useCallback((questions: typeof filteredQuestions, sessionType: string) => {
236-
setRecommendedQuestions(questions);
237-
setCurrentQuestionIndex(0);
238-
setShowExplanation(false);
239-
setShowRecommendations(false);
240-
}, []);
241-
242-
const handleExitRecommendedSession = useCallback(() => {
243-
setRecommendedQuestions([]);
244-
setCurrentQuestionIndex(0);
245-
setShowExplanation(false);
246-
}, []);
247-
248-
const handleStartFlashcards = useCallback(() => {
249-
setShowFlashcards(true);
250-
}, []);
251-
252-
const handleExitFlashcards = useCallback(() => {
253-
setShowFlashcards(false);
254-
}, []);
255201

256202
// Calculate question counts for filters
257203
const questionCounts = {

0 commit comments

Comments
 (0)