mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 22:37:10 +00:00
Merge branch 'master' of gitlab.prodcontest.ru:team-15/project
This commit is contained in:
@@ -4,6 +4,7 @@ import CompetitionHeader from "./components/CompetitionHeader";
|
|||||||
import TaskContent from "./components/TaskContent";
|
import TaskContent from "./components/TaskContent";
|
||||||
import TaskSolution from "./modules/TaskSolution";
|
import TaskSolution from "./modules/TaskSolution";
|
||||||
import { getCompetitionTasks, submitTaskSolution } from "@/shared/api/session";
|
import { getCompetitionTasks, submitTaskSolution } from "@/shared/api/session";
|
||||||
|
import { getCompetition } from "@/shared/api/competitions";
|
||||||
import { Loader2 } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { TaskType } from "@/shared/types/task";
|
import { TaskType } from "@/shared/types/task";
|
||||||
@@ -15,6 +16,12 @@ const CompetitionSession = () => {
|
|||||||
const competitionId = id || "";
|
const competitionId = id || "";
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const competitionQuery = useQuery({
|
||||||
|
queryKey: ["competition", competitionId],
|
||||||
|
queryFn: () => getCompetition(competitionId),
|
||||||
|
enabled: !!competitionId,
|
||||||
|
});
|
||||||
|
|
||||||
const tasksQuery = useQuery({
|
const tasksQuery = useQuery({
|
||||||
queryKey: ["competitionTasks", competitionId],
|
queryKey: ["competitionTasks", competitionId],
|
||||||
queryFn: () => getCompetitionTasks(competitionId),
|
queryFn: () => getCompetitionTasks(competitionId),
|
||||||
@@ -46,9 +53,12 @@ const CompetitionSession = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const competition = competitionQuery.data;
|
||||||
const tasks = tasksQuery.data || [];
|
const tasks = tasksQuery.data || [];
|
||||||
const isLoading = tasksQuery.isLoading;
|
const isLoading = tasksQuery.isLoading || competitionQuery.isLoading;
|
||||||
const error = tasksQuery.error ? "Не удалось загрузить задания. Пожалуйста, попробуйте позже." : null;
|
const error = tasksQuery.error || competitionQuery.error
|
||||||
|
? "Не удалось загрузить данные. Пожалуйста, попробуйте позже."
|
||||||
|
: null;
|
||||||
|
|
||||||
const currentTask = tasks.find((t) => t.id === taskId) || null;
|
const currentTask = tasks.find((t) => t.id === taskId) || null;
|
||||||
|
|
||||||
@@ -77,10 +87,12 @@ const CompetitionSession = () => {
|
|||||||
submitMutation.mutate();
|
submitMutation.mutate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const competitionTitle = competition?.title || "Загрузка соревнования...";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen flex-col">
|
<div className="flex min-h-screen flex-col">
|
||||||
<CompetitionHeader
|
<CompetitionHeader
|
||||||
title="Олимпиада DANO 2025. Индивидуальный этап"
|
title={competitionTitle}
|
||||||
tasks={tasks}
|
tasks={tasks}
|
||||||
competitionId={competitionId}
|
competitionId={competitionId}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+1
-18
@@ -99,7 +99,7 @@ const FileSolution: React.FC<FileSolutionProps> = ({
|
|||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{selectedFile ? (
|
{selectedFile || existingFileUrl ? (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
className="text-sm p-0 h-auto hover:bg-transparent font-hse-sans"
|
className="text-sm p-0 h-auto hover:bg-transparent font-hse-sans"
|
||||||
@@ -107,23 +107,6 @@ const FileSolution: React.FC<FileSolutionProps> = ({
|
|||||||
>
|
>
|
||||||
Очистить
|
Очистить
|
||||||
</Button>
|
</Button>
|
||||||
) : existingFileUrl ? (
|
|
||||||
<div className="flex gap-3">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
className="text-sm p-0 h-auto hover:bg-transparent font-hse-sans"
|
|
||||||
onClick={handleSelectNewFile}
|
|
||||||
>
|
|
||||||
Выбрать другой файл
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
className="text-sm p-0 h-auto hover:bg-transparent font-hse-sans"
|
|
||||||
onClick={handleClearFile}
|
|
||||||
>
|
|
||||||
Очистить
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
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 [currentSolution, setCurrentSolution] = useState<Solution | null>(null);
|
||||||
const { id: competitionId } = useParams<{ id: string }>();
|
const { id: competitionId } = useParams<{ id: string }>();
|
||||||
|
const previousTaskIdRef = useRef<string | null>(null);
|
||||||
|
|
||||||
const solutionsQuery = useQuery({
|
const solutionsQuery = useQuery({
|
||||||
queryKey: ['solutionHistory', competitionId, task.id],
|
queryKey: ['solutionHistory', competitionId, task.id],
|
||||||
@@ -39,48 +41,46 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const solutionHistory = solutionsQuery.data || [];
|
const solutionHistory = solutionsQuery.data || [];
|
||||||
const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[0] : null;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadLatestSolution = async () => {
|
if (solutionHistory.length > 0 && !currentSolution) {
|
||||||
if (!latestSolution || !latestSolution.content) return;
|
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
||||||
|
}
|
||||||
|
}, [solutionHistory, currentSolution]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (solutionHistory.length > 0 && currentSolution &&
|
||||||
|
solutionHistory[0].id !== currentSolution.id) {
|
||||||
|
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
||||||
|
}
|
||||||
|
}, [solutionHistory, currentSolution]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (previousTaskIdRef.current !== task.id) {
|
||||||
|
setCurrentSolution(null);
|
||||||
|
setSelectedSolutionUrl(null);
|
||||||
|
|
||||||
|
setAnswer("");
|
||||||
|
setSelectedFile(null);
|
||||||
|
|
||||||
|
if (solutionHistory.length > 0 && !solutionsQuery.isLoading) {
|
||||||
|
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
previousTaskIdRef.current = task.id;
|
||||||
|
}
|
||||||
|
}, [task.id, solutionHistory, solutionsQuery.isLoading, setAnswer, setSelectedFile]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadSolutionContent = async () => {
|
||||||
|
if (!currentSolution || !currentSolution.content) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (task.type === TaskType.FILE) {
|
if (task.type === TaskType.FILE) {
|
||||||
setSelectedFile(null);
|
setSelectedFile(null);
|
||||||
setSelectedSolutionUrl(latestSolution.content);
|
setSelectedSolutionUrl(currentSolution.content);
|
||||||
} else {
|
} else {
|
||||||
const response = await fetch(latestSolution.content);
|
const response = await fetch(currentSolution.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 handleSolutionSelect = async (solution: Solution) => {
|
|
||||||
if (!solution.content) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (task.type === TaskType.FILE) {
|
|
||||||
setSelectedFile(null);
|
|
||||||
setSelectedSolutionUrl(solution.content);
|
|
||||||
} else {
|
|
||||||
const response = await fetch(solution.content);
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to fetch solution content: ${response.status}`);
|
throw new Error(`Failed to fetch solution content: ${response.status}`);
|
||||||
}
|
}
|
||||||
@@ -92,14 +92,26 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
loadSolutionContent();
|
||||||
|
}, [currentSolution, task.type, setAnswer, setSelectedFile]);
|
||||||
|
|
||||||
|
const handleOpenHistory = () => {
|
||||||
|
setIsHistoryOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSolutionSelect = (solution: Solution) => {
|
||||||
|
setCurrentSolution(solution);
|
||||||
|
setIsHistoryOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
const handleClearExistingFile = () => {
|
const handleClearExistingFile = () => {
|
||||||
setSelectedSolutionUrl(null);
|
setSelectedSolutionUrl(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="md:w-[500px] flex flex-col gap-4">
|
<div className="md:w-[500px] flex flex-col gap-4">
|
||||||
{latestSolution ? (
|
{currentSolution ? (
|
||||||
<SolutionStatus solution={latestSolution} maxPoints={task.points}/>
|
<SolutionStatus solution={currentSolution} maxPoints={task.points}/>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-gray-100 rounded-lg p-4 text-gray-600 font-hse-sans">
|
<div className="bg-gray-100 rounded-lg p-4 text-gray-600 font-hse-sans">
|
||||||
Решение еще не отправлено
|
Решение еще не отправлено
|
||||||
@@ -141,6 +153,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
solutions={solutionHistory}
|
solutions={solutionHistory}
|
||||||
maxPoints={task.points}
|
maxPoints={task.points}
|
||||||
onSolutionSelect={handleSolutionSelect}
|
onSolutionSelect={handleSolutionSelect}
|
||||||
|
currentSolutionId={currentSolution?.id}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user