From 664ded152a8112abbe47a983ce8c9417e393e444 Mon Sep 17 00:00:00 2001 From: rngsurrounded Date: Mon, 3 Mar 2025 22:04:25 +0900 Subject: [PATCH] test fix --- .../components/CompetitionHeader/index.tsx | 1 - .../modules/TaskSolution/index.tsx | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx index d4bab74..086abb1 100644 --- a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx @@ -24,7 +24,6 @@ const CompetitionHeader: React.FC = ({ const handleTaskSelect = (taskId: string) => { setAnswer(""); setSelectedFile(null); - console.log("SETTER ERROR") navigate(`/competition/${competitionId}/tasks/${taskId}`); } diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx index 5267dbb..8d4051e 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx @@ -81,13 +81,24 @@ const TaskSolution: React.FC = ({ useEffect(() => { const loadSolutionContent = async () => { + // Clear previous inputs when task changes + if (prevTaskIdRef.current !== task.id) { + setAnswer(""); + setSelectedFile(null); + setSelectedSolutionUrl(null); + prevTaskIdRef.current = task.id; + } + if (!displayedSolution || !displayedSolution.content) return; try { + // Only load content for the appropriate task type if (task.type === TaskType.FILE) { + // For file tasks, we just set the URL - don't touch the answer field setSelectedFile(null); setSelectedSolutionUrl(displayedSolution.content); - } else { + } else if (task.type === TaskType.CODE || task.type === TaskType.INPUT) { + // For non-file tasks, fetch and set the answer text - don't touch file fields const response = await fetch(displayedSolution.content); if (!response.ok) { throw new Error(`Failed to fetch solution content: ${response.status}`); @@ -99,9 +110,9 @@ const TaskSolution: React.FC = ({ console.error('Error loading solution content:', error); } }; - + loadSolutionContent(); - }, [displayedSolution, task.type, setAnswer, setSelectedFile]); + }, [displayedSolution, task.id, task.type, setAnswer, setSelectedFile]); const handleOpenHistory = () => { setIsHistoryOpen(true);