mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 19:07:10 +00:00
fix check
This commit is contained in:
+11
-6
@@ -2,13 +2,14 @@ import React from 'react';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Task } from '@/shared/types/task';
|
import { Task } from '@/shared/types/task';
|
||||||
import { ArrowLeft } from 'lucide-react';
|
import { ArrowLeft } from 'lucide-react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
interface CompetitionHeaderProps {
|
interface CompetitionHeaderProps {
|
||||||
title: string;
|
title: string;
|
||||||
tasks: Task[];
|
tasks: Task[];
|
||||||
competitionId: string;
|
competitionId: string;
|
||||||
setAnswer: (value: string) => void;
|
setAnswer: (value: string) => void;
|
||||||
setSelectedFile: (file: File | null) => void; // заглушка
|
setSelectedFile: (file: File | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
||||||
@@ -18,11 +19,15 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
|||||||
setAnswer,
|
setAnswer,
|
||||||
setSelectedFile
|
setSelectedFile
|
||||||
}) => {
|
}) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleTaskSelect = () => {
|
const handleTaskSelect = (event: React.MouseEvent, taskId: string) => {
|
||||||
setAnswer("")
|
event.preventDefault();
|
||||||
setSelectedFile(null)
|
setAnswer("");
|
||||||
console.log("STOP IT")
|
setSelectedFile(null);
|
||||||
|
console.log("link check");
|
||||||
|
|
||||||
|
navigate(`/competition/${competitionId}/tasks/${taskId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -32,7 +37,6 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
|||||||
<Link
|
<Link
|
||||||
to={`/competition/${competitionId}`}
|
to={`/competition/${competitionId}`}
|
||||||
className="flex items-center text-gray-600 hover:text-gray-900 transition-colors font-hse-sans text-sm"
|
className="flex items-center text-gray-600 hover:text-gray-900 transition-colors font-hse-sans text-sm"
|
||||||
onClick={handleTaskSelect}
|
|
||||||
>
|
>
|
||||||
<ArrowLeft className="h-4 w-4 mr-1" />
|
<ArrowLeft className="h-4 w-4 mr-1" />
|
||||||
</Link>
|
</Link>
|
||||||
@@ -53,6 +57,7 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
|||||||
rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
||||||
transition-all hover:brightness-95 flex-shrink-0
|
transition-all hover:brightness-95 flex-shrink-0
|
||||||
`}
|
`}
|
||||||
|
onClick={(e) => handleTaskSelect(e, task.id)}
|
||||||
>
|
>
|
||||||
{task.in_competition_position}
|
{task.in_competition_position}
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,168 +1,163 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { Task, TaskType, Solution } from '@/shared/types/task';
|
import { Task, TaskType, Solution } from '@/shared/types/task';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { getTaskSolutionHistory } from '@/shared/api/session';
|
import { getTaskSolutionHistory } from '@/shared/api/session';
|
||||||
import SolutionStatus from './components/SolutionStatus';
|
import SolutionStatus from './components/SolutionStatus';
|
||||||
import InputSolution from './components/InputSolution';
|
import InputSolution from './components/InputSolution';
|
||||||
import FileSolution from './components/FileSolution';
|
import FileSolution from './components/FileSolution';
|
||||||
import CodeSolution from './components/CodeSolution';
|
import CodeSolution from './components/CodeSolution';
|
||||||
import ActionButtons from './components/ActionButtons';
|
import ActionButtons from './components/ActionButtons';
|
||||||
import SolutionHistorySheet from './components/SolutionHistorySheet';
|
import SolutionHistorySheet from './components/SolutionHistorySheet';
|
||||||
|
|
||||||
interface TaskSolutionProps {
|
interface TaskSolutionProps {
|
||||||
task: Task;
|
task: Task;
|
||||||
answer: string;
|
answer: string;
|
||||||
setAnswer: (value: string) => void;
|
setAnswer: (value: string) => void;
|
||||||
selectedFile: File | null;
|
selectedFile: File | null;
|
||||||
setSelectedFile: (file: File | null) => void;
|
setSelectedFile: (file: File | null) => void;
|
||||||
onSubmit: () => void;
|
onSubmit: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||||
task,
|
task,
|
||||||
answer,
|
answer,
|
||||||
setAnswer,
|
setAnswer,
|
||||||
selectedFile,
|
selectedFile,
|
||||||
setSelectedFile,
|
setSelectedFile,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}) => {
|
}) => {
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
||||||
const [selectedSolutionUrl, setSelectedSolutionUrl] = useState<string | null>(null);
|
const [selectedSolutionUrl, setSelectedSolutionUrl] = useState<string | null>(null);
|
||||||
const [displayedSolution, setDisplayedSolution] = useState<Solution | null>(null);
|
const [displayedSolution, setDisplayedSolution] = useState<Solution | null>(null);
|
||||||
const { id: competitionId } = useParams<{ id: string }>();
|
const { id: competitionId } = useParams<{ id: string }>();
|
||||||
const prevTaskIdRef = useRef<string | null>(null);
|
const prevTaskIdRef = useRef<string | null>(null);
|
||||||
|
|
||||||
const solutionsQuery = useQuery({
|
const solutionsQuery = useQuery({
|
||||||
queryKey: ['solutionHistory', competitionId, task.id],
|
queryKey: ['solutionHistory', competitionId, task.id],
|
||||||
queryFn: () => getTaskSolutionHistory(competitionId || '', task.id),
|
queryFn: () => getTaskSolutionHistory(competitionId || '', task.id),
|
||||||
enabled: !!(competitionId && task.id),
|
enabled: !!(competitionId && task.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
const solutionHistory = solutionsQuery.data || [];
|
const solutionHistory = solutionsQuery.data || [];
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (solutionHistory.length > 0 && !displayedSolution) {
|
if (solutionHistory.length > 0 && !displayedSolution) {
|
||||||
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
|
||||||
setDisplayedSolution(latestSolution);
|
|
||||||
}
|
|
||||||
}, [solutionHistory, displayedSolution]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (prevTaskIdRef.current !== task.id) {
|
|
||||||
setDisplayedSolution(null);
|
|
||||||
setSelectedSolutionUrl(null);
|
|
||||||
|
|
||||||
// If solutions are already loaded for the new task, set the latest one
|
|
||||||
if (solutionHistory.length > 0) {
|
|
||||||
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
||||||
setDisplayedSolution(latestSolution);
|
setDisplayedSolution(latestSolution);
|
||||||
}
|
}
|
||||||
|
}, [solutionHistory, displayedSolution]);
|
||||||
|
|
||||||
prevTaskIdRef.current = task.id;
|
useEffect(() => {
|
||||||
}
|
if (prevTaskIdRef.current !== task.id) {
|
||||||
}, [task.id, solutionHistory]);
|
setDisplayedSolution(null);
|
||||||
|
setSelectedSolutionUrl(null);
|
||||||
|
|
||||||
// Check if a new solution was submitted (latest solution ID changed)
|
if (solutionHistory.length > 0) {
|
||||||
useEffect(() => {
|
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
||||||
if (solutionHistory.length > 0 && displayedSolution) {
|
setDisplayedSolution(latestSolution);
|
||||||
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, displayedSolution]);
|
|
||||||
|
|
||||||
// Load solution content when the displayed solution changes
|
|
||||||
useEffect(() => {
|
|
||||||
const loadSolutionContent = async () => {
|
|
||||||
if (!displayedSolution || !displayedSolution.content) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (task.type === TaskType.FILE) {
|
|
||||||
setSelectedFile(null);
|
|
||||||
setSelectedSolutionUrl(displayedSolution.content);
|
|
||||||
} else {
|
|
||||||
const response = await fetch(displayedSolution.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 solution content:', error);
|
prevTaskIdRef.current = task.id;
|
||||||
}
|
}
|
||||||
|
}, [task.id, solutionHistory]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (solutionHistory.length > 0 && displayedSolution) {
|
||||||
|
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
||||||
|
|
||||||
|
if (latestSolution.id !== displayedSolution.id) {
|
||||||
|
setDisplayedSolution(latestSolution);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [solutionHistory, displayedSolution]);
|
||||||
|
|
||||||
|
// Load solution content when the displayed solution changes
|
||||||
|
useEffect(() => {
|
||||||
|
const loadSolutionContent = async () => {
|
||||||
|
if (!displayedSolution || !displayedSolution.content) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (task.type === TaskType.FILE) {
|
||||||
|
setSelectedFile(null);
|
||||||
|
setSelectedSolutionUrl(displayedSolution.content);
|
||||||
|
} else {
|
||||||
|
const response = await fetch(displayedSolution.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 solution content:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadSolutionContent();
|
||||||
|
}, [displayedSolution, task.type, setAnswer, setSelectedFile]);
|
||||||
|
|
||||||
|
const handleOpenHistory = () => {
|
||||||
|
setIsHistoryOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
loadSolutionContent();
|
const handleSolutionSelect = (solution: Solution) => {
|
||||||
}, [displayedSolution, task.type, setAnswer, setSelectedFile]);
|
setDisplayedSolution(solution);
|
||||||
|
};
|
||||||
|
|
||||||
const handleOpenHistory = () => {
|
const handleClearExistingFile = () => {
|
||||||
setIsHistoryOpen(true);
|
setSelectedSolutionUrl(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="md:w-[500px] flex flex-col gap-4">
|
||||||
|
{displayedSolution ? (
|
||||||
|
<SolutionStatus solution={displayedSolution} maxPoints={task.points}/>
|
||||||
|
) : (
|
||||||
|
<div className="bg-gray-100 rounded-lg p-4 text-gray-600 font-hse-sans">
|
||||||
|
Решение еще не отправлено
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{task.type === TaskType.INPUT && (
|
||||||
|
<InputSolution
|
||||||
|
answer={answer}
|
||||||
|
setAnswer={setAnswer}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{task.type === TaskType.FILE && (
|
||||||
|
<FileSolution
|
||||||
|
selectedFile={selectedFile}
|
||||||
|
setSelectedFile={setSelectedFile}
|
||||||
|
fileInputRef={fileInputRef}
|
||||||
|
existingFileUrl={selectedSolutionUrl}
|
||||||
|
onClearExistingFile={handleClearExistingFile}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{task.type === TaskType.CODE && (
|
||||||
|
<CodeSolution
|
||||||
|
answer={answer}
|
||||||
|
setAnswer={setAnswer}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<ActionButtons
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
onHistoryClick={handleOpenHistory}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SolutionHistorySheet
|
||||||
|
isOpen={isHistoryOpen}
|
||||||
|
onOpenChange={setIsHistoryOpen}
|
||||||
|
solutions={solutionHistory}
|
||||||
|
maxPoints={task.points}
|
||||||
|
onSolutionSelect={handleSolutionSelect}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSolutionSelect = (solution: Solution) => {
|
export default TaskSolution;
|
||||||
setDisplayedSolution(solution);
|
|
||||||
console.log(displayedSolution)
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClearExistingFile = () => {
|
|
||||||
setSelectedSolutionUrl(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="md:w-[500px] flex flex-col gap-4">
|
|
||||||
{displayedSolution ? (
|
|
||||||
<SolutionStatus solution={displayedSolution} maxPoints={task.points}/>
|
|
||||||
) : (
|
|
||||||
<div className="bg-gray-100 rounded-lg p-4 text-gray-600 font-hse-sans">
|
|
||||||
Решение еще не отправлено
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{task.type === TaskType.INPUT && (
|
|
||||||
<InputSolution
|
|
||||||
answer={answer}
|
|
||||||
setAnswer={setAnswer}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{task.type === TaskType.FILE && (
|
|
||||||
<FileSolution
|
|
||||||
selectedFile={selectedFile}
|
|
||||||
setSelectedFile={setSelectedFile}
|
|
||||||
fileInputRef={fileInputRef}
|
|
||||||
existingFileUrl={selectedSolutionUrl}
|
|
||||||
onClearExistingFile={handleClearExistingFile}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{task.type === TaskType.CODE && (
|
|
||||||
<CodeSolution
|
|
||||||
answer={answer}
|
|
||||||
setAnswer={setAnswer}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ActionButtons
|
|
||||||
onSubmit={onSubmit}
|
|
||||||
onHistoryClick={handleOpenHistory}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SolutionHistorySheet
|
|
||||||
isOpen={isHistoryOpen}
|
|
||||||
onOpenChange={setIsHistoryOpen}
|
|
||||||
solutions={solutionHistory}
|
|
||||||
maxPoints={task.points}
|
|
||||||
onSolutionSelect={handleSolutionSelect}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default TaskSolution;
|
|
||||||
Reference in New Issue
Block a user