From 87872fbdecb8e7f34628f25bf407a8c12984450a Mon Sep 17 00:00:00 2001 From: rngsurrounded Date: Mon, 3 Mar 2025 05:56:40 +0900 Subject: [PATCH] fix file submissions --- .../components/FileSolution/index.tsx | 61 ++++++++++++++++--- .../modules/TaskSolution/index.tsx | 17 ++++-- .../components/CompetitionCard/index.tsx | 2 +- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/FileSolution/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/FileSolution/index.tsx index cd2b1d4..4be1f55 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/FileSolution/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/FileSolution/index.tsx @@ -7,17 +7,23 @@ interface FileSolutionProps { setSelectedFile: (file: File | null) => void; fileInputRef: React.RefObject; existingFileUrl?: string | null; + onClearExistingFile?: () => void; // New prop to clear existing file URL } const FileSolution: React.FC = ({ selectedFile, setSelectedFile, fileInputRef, - existingFileUrl = null + existingFileUrl = null, + onClearExistingFile }) => { const handleFileChange = (event: React.ChangeEvent) => { if (event.target.files && event.target.files[0]) { setSelectedFile(event.target.files[0]); + // Clear existing file URL when a new file is selected + if (existingFileUrl && onClearExistingFile) { + onClearExistingFile(); + } } }; @@ -41,9 +47,28 @@ const FileSolution: React.FC = ({ if (e.dataTransfer.files && e.dataTransfer.files[0]) { setSelectedFile(e.dataTransfer.files[0]); + // Clear existing file URL when a new file is dropped + if (existingFileUrl && onClearExistingFile) { + onClearExistingFile(); + } } }; + // Handle clearing the file + const handleClearFile = () => { + setSelectedFile(null); + // Also clear the existing file URL if it exists + if (existingFileUrl && onClearExistingFile) { + onClearExistingFile(); + } + }; + + // Handle selecting a new file when an existing file is shown + const handleSelectNewFile = () => { + // Just trigger the file input click - the actual clearing will happen in handleFileChange + fileInputRef.current?.click(); + }; + const fileName = selectedFile ? selectedFile.name : existingFileUrl @@ -79,13 +104,33 @@ const FileSolution: React.FC = ({ Скачать )} - + + {selectedFile ? ( + + ) : existingFileUrl ? ( +
+ + +
+ ) : null} diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx index d78f313..833e1d2 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx @@ -44,15 +44,18 @@ const TaskSolution: React.FC = ({ setIsHistoryOpen(true); }; - const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[solutionHistory.length - 1] : null; + const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[0] : null; const handleSolutionSelect = async (solution: Solution) => { if (!solution.content) return; - setSelectedSolutionUrl(solution.content); - try { - if (task.type !== TaskType.FILE) { + if (task.type === TaskType.FILE) { + // For file tasks, just store the URL + setSelectedFile(null); // Clear any selected file first + 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}`); @@ -65,6 +68,11 @@ const TaskSolution: React.FC = ({ } }; + // Function to clear the existing file URL + const handleClearExistingFile = () => { + setSelectedSolutionUrl(null); + }; + return (
{latestSolution ? ( @@ -85,6 +93,7 @@ const TaskSolution: React.FC = ({ setSelectedFile={setSelectedFile} fileInputRef={fileInputRef} existingFileUrl={selectedSolutionUrl} + onClearExistingFile={handleClearExistingFile} /> )} diff --git a/services/frontend/src/pages/Competitions/components/CompetitionCard/index.tsx b/services/frontend/src/pages/Competitions/components/CompetitionCard/index.tsx index dd6d3db..ddbc19b 100644 --- a/services/frontend/src/pages/Competitions/components/CompetitionCard/index.tsx +++ b/services/frontend/src/pages/Competitions/components/CompetitionCard/index.tsx @@ -55,7 +55,7 @@ export function CompetitionCard({ {competition.state === CompetitionState.STARTED - ? "В прогрессе" + ? "Проводится сейчас" : "Завершено"}