diff --git a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx index 96f990b..b4eba1b 100644 --- a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx @@ -23,7 +23,6 @@ const CompetitionHeader: React.FC = ({ className="flex items-center text-gray-600 hover:text-gray-900 transition-colors font-hse-sans text-sm" > - Обратно

diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx index 833e1d2..e2262f9 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef } from 'react'; +import React, { useState, useRef, useEffect } from 'react'; import { useParams } from 'react-router-dom'; import { Task, TaskType, Solution } from '@/shared/types/task'; import { useQuery } from '@tanstack/react-query'; @@ -39,23 +39,47 @@ const TaskSolution: React.FC = ({ }); const solutionHistory = solutionsQuery.data || []; + const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[0] : null; + + useEffect(() => { + const loadLatestSolution = async () => { + if (!latestSolution || !latestSolution.content) return; + + try { + if (task.type === TaskType.FILE) { + setSelectedFile(null); + setSelectedSolutionUrl(latestSolution.content); + } else { + const response = await fetch(latestSolution.content); + if (!response.ok) { + throw new Error(`Failed to fetch solution content: ${response.status}`); + } + const text = await response.text(); + setAnswer(text); + } + } catch (error) { + console.error('Error loading latest solution content:', error); + } finally { + } + }; + + if (latestSolution && !solutionsQuery.isLoading && !solutionsQuery.isError) { + loadLatestSolution(); + } + }, [latestSolution, task.id, task.type, setAnswer, setSelectedFile]); const handleOpenHistory = () => { setIsHistoryOpen(true); }; - const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[0] : null; - const handleSolutionSelect = async (solution: Solution) => { if (!solution.content) return; try { if (task.type === TaskType.FILE) { - // For file tasks, just store the URL - setSelectedFile(null); // Clear any selected file first + setSelectedFile(null); setSelectedSolutionUrl(solution.content); } else { - // For INPUT and CODE tasks, fetch the content and set as answer const response = await fetch(solution.content); if (!response.ok) { throw new Error(`Failed to fetch solution content: ${response.status}`); @@ -68,7 +92,6 @@ const TaskSolution: React.FC = ({ } }; - // Function to clear the existing file URL const handleClearExistingFile = () => { setSelectedSolutionUrl(null); }; @@ -84,7 +107,10 @@ const TaskSolution: React.FC = ({ )} {task.type === TaskType.INPUT && ( - + )} {task.type === TaskType.FILE && ( @@ -94,11 +120,15 @@ const TaskSolution: React.FC = ({ fileInputRef={fileInputRef} existingFileUrl={selectedSolutionUrl} onClearExistingFile={handleClearExistingFile} + isLoading={isInitialLoading} /> )} {task.type === TaskType.CODE && ( - + )}