diff --git a/services/backend/apps/task/tasks.py b/services/backend/apps/task/tasks.py index bb909c2..86588f4 100644 --- a/services/backend/apps/task/tasks.py +++ b/services/backend/apps/task/tasks.py @@ -12,9 +12,7 @@ from apps.task.models import CompetitionTaskSubmission def analyze_data_task(self, submission_id): submission = CompetitionTaskSubmission.objects.get(id=submission_id) try: - code_url = ( - f"{settings.MINIO_DEFAULT_CUSTOM_ENDPOINT_URL}{submission.path}" - ) + code_url = f"{settings.MINIO_DEFAULT_CUSTOM_ENDPOINT_URL}{submission.content.path}" files = [ { "url": f"{settings.MINIO_DEFAULT_CUSTOM_ENDPOINT_URL}{attachment.path}", diff --git a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx index b4eba1b..6d36a6b 100644 --- a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx @@ -7,13 +7,23 @@ interface CompetitionHeaderProps { title: string; tasks: Task[]; competitionId: string; + setAnswer: (value: string) => void; + setSelectedFile: (file: File | null) => void; // заглушка } const CompetitionHeader: React.FC = ({ title, tasks, - competitionId + competitionId, + setAnswer, + setSelectedFile }) => { + + const handleTaskSelect = () => { + setAnswer("") + setSelectedFile(null) + } + return (
@@ -21,6 +31,7 @@ const CompetitionHeader: React.FC = ({ diff --git a/services/frontend/src/pages/CompetitionSession/index.tsx b/services/frontend/src/pages/CompetitionSession/index.tsx index 4d0c5f8..eb80913 100644 --- a/services/frontend/src/pages/CompetitionSession/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/index.tsx @@ -95,6 +95,8 @@ const CompetitionSession = () => { title={competitionTitle} tasks={tasks} competitionId={competitionId} + setAnswer={setAnswer} + setSelectedFile={setSelectedFile} />
diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionHistorySheet/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionHistorySheet/index.tsx index 83d8cda..1abcabb 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionHistorySheet/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionHistorySheet/index.tsx @@ -11,7 +11,7 @@ interface SolutionHistorySheetProps { solutions: Solution[]; maxPoints: number; onSolutionSelect: (solution: Solution) => void; - currentSolutionId?: string | null; + currentSolutionId?: string; } const SolutionHistorySheet: React.FC = ({ @@ -22,7 +22,6 @@ const SolutionHistorySheet: React.FC = ({ onSolutionSelect, currentSolutionId }) => { - return ( @@ -39,11 +38,15 @@ const SolutionHistorySheet: React.FC = ({
{solutions.length > 0 ? ( - solutions.map((solution) => ( + solutions.map((solution, index) => (
onSolutionSelect(solution)} + key={solution.id || index} + className={`w-full cursor-pointer transition-transform hover:scale-[1.01] relative + ${solution.id === currentSolutionId ? 'ring-2 ring-blue-500 rounded-lg' : ''}`} + onClick={() => { + onSolutionSelect(solution); + onOpenChange(false); + }} > {solution.id === currentSolutionId && (
diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionStatus/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionStatus/index.tsx index b67c5ac..8596c97 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionStatus/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/SolutionStatus/index.tsx @@ -11,6 +11,7 @@ const SolutionStatus: React.FC = ({ solution, maxPoints }) => { const formattedDate = solution.timestamp ? format(parseISO(solution.timestamp), "d MMMM, HH:mm", { locale: ru }) : ''; + console.log(solution, "SOLUTION STATUS") return (
diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx index 06cebdd..87cd253 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx @@ -9,6 +9,8 @@ import FileSolution from './components/FileSolution'; import CodeSolution from './components/CodeSolution'; import ActionButtons from './components/ActionButtons'; import SolutionHistorySheet from './components/SolutionHistorySheet'; +import { AlertTriangle, ArrowRight } from 'lucide-react'; +import { Button } from '@/components/ui/button'; interface TaskSolutionProps { task: Task; @@ -17,6 +19,7 @@ interface TaskSolutionProps { selectedFile: File | null; setSelectedFile: (file: File | null) => void; onSubmit: () => void; + isSubmitting?: boolean; } const TaskSolution: React.FC = ({ @@ -26,13 +29,14 @@ const TaskSolution: React.FC = ({ selectedFile, setSelectedFile, onSubmit, + isSubmitting = false }) => { const fileInputRef = useRef(null); const [isHistoryOpen, setIsHistoryOpen] = useState(false); const [selectedSolutionUrl, setSelectedSolutionUrl] = useState(null); - const [currentSolution, setCurrentSolution] = useState(null); + const [displayedSolution, setDisplayedSolution] = useState(null); const { id: competitionId } = useParams<{ id: string }>(); - const taskIdRef = useRef(null); + const prevTaskIdRef = useRef(null); const solutionsQuery = useQuery({ queryKey: ['solutionHistory', competitionId, task.id], @@ -41,48 +45,66 @@ const TaskSolution: React.FC = ({ }); const solutionHistory = solutionsQuery.data || []; - // Handle task changes + + const getLatestSolution = () => { + return solutionHistory.length > 0 ? solutionHistory[solutionHistory.length - 1] : null; + }; + + const isOutdatedSolution = () => { + if (!displayedSolution || solutionHistory.length === 0) return false; + const latestSolution = getLatestSolution(); + return latestSolution?.id !== displayedSolution.id; + }; + + // Set initial solution to the last one (most recent) when solutions are loaded useEffect(() => { - if (taskIdRef.current !== task.id) { - setCurrentSolution(null); + if (solutionHistory.length > 0 && !displayedSolution) { + const latestSolution = solutionHistory[solutionHistory.length - 1]; + setDisplayedSolution(latestSolution); + } + }, [solutionHistory, displayedSolution]); + + // When task changes, reset everything and load the latest solution for the new task + useEffect(() => { + if (prevTaskIdRef.current !== task.id) { + // Reset states for new task + setDisplayedSolution(null); setSelectedSolutionUrl(null); - setAnswer(""); - setSelectedFile(null); - taskIdRef.current = task.id; - // Wait for the query to complete - if (!solutionsQuery.isLoading && solutionHistory.length > 0) { - // Get the most recent solution (last in the array) + // If solutions are already loaded for the new task, set the latest one + if (solutionHistory.length > 0) { const latestSolution = solutionHistory[solutionHistory.length - 1]; - setCurrentSolution(latestSolution); + setDisplayedSolution(latestSolution); } + + prevTaskIdRef.current = task.id; } - }, [task.id, solutionHistory, solutionsQuery.isLoading, setAnswer, setSelectedFile]); + }, [task.id, solutionHistory]); - // Refresh current solution when the solution history changes (after a new submission) + // Check if a new solution was submitted (latest solution ID changed) useEffect(() => { - if (!solutionsQuery.isLoading && solutionHistory.length > 0) { - // If we don't have a current solution or there's a new submission - // (which would be the last item in the array) - if (!currentSolution || - currentSolution.id !== solutionHistory[solutionHistory.length - 1].id) { - // Set to the latest solution (last in the array) - setCurrentSolution(solutionHistory[solutionHistory.length - 1]); + if (solutionHistory.length > 0 && displayedSolution) { + const latestSolution = solutionHistory[solutionHistory.length - 1]; + + // If the latest solution ID is different from the displayed one, + // a new solution was submitted - update to show the latest + if (latestSolution.id !== displayedSolution.id) { + setDisplayedSolution(latestSolution); } } - }, [solutionHistory, currentSolution, solutionsQuery.isLoading]); + }, [solutionHistory, displayedSolution]); - // Load solution content when current solution changes + // Load solution content when the displayed solution changes useEffect(() => { const loadSolutionContent = async () => { - if (!currentSolution || !currentSolution.content) return; + if (!displayedSolution || !displayedSolution.content) return; try { if (task.type === TaskType.FILE) { setSelectedFile(null); - setSelectedSolutionUrl(currentSolution.content); + setSelectedSolutionUrl(displayedSolution.content); } else { - const response = await fetch(currentSolution.content); + const response = await fetch(displayedSolution.content); if (!response.ok) { throw new Error(`Failed to fetch solution content: ${response.status}`); } @@ -95,39 +117,61 @@ const TaskSolution: React.FC = ({ }; loadSolutionContent(); - }, [currentSolution, task.type, setAnswer, setSelectedFile]); + }, [displayedSolution, task.type, setAnswer, setSelectedFile]); const handleOpenHistory = () => { setIsHistoryOpen(true); }; const handleSolutionSelect = (solution: Solution) => { - setCurrentSolution(solution); - setIsHistoryOpen(false); + setDisplayedSolution(solution); }; const handleClearExistingFile = () => { setSelectedSolutionUrl(null); }; - - const handleSubmitWrapper = () => { - onSubmit(); + + // Function to switch to the latest solution + const goToLatestSolution = () => { + const latestSolution = getLatestSolution(); + if (latestSolution) { + setDisplayedSolution(latestSolution); + } }; return (
- {currentSolution ? ( - + {displayedSolution ? ( + ) : (
Решение еще не отправлено
)} + {/* Outdated solution warning */} + {isOutdatedSolution() && ( +
+
+ + Устаревшая посылка +
+ +
+ )} + {task.type === TaskType.INPUT && ( )} @@ -138,6 +182,7 @@ const TaskSolution: React.FC = ({ fileInputRef={fileInputRef} existingFileUrl={selectedSolutionUrl} onClearExistingFile={handleClearExistingFile} + isLoading={isSubmitting} /> )} @@ -149,7 +194,7 @@ const TaskSolution: React.FC = ({ )} @@ -159,7 +204,7 @@ const TaskSolution: React.FC = ({ solutions={solutionHistory} maxPoints={task.points} onSolutionSelect={handleSolutionSelect} - currentSolutionId={currentSolution?.id} + currentSolutionId={displayedSolution?.id} />
);