import { useState, useEffect } from "react"; import { useParams, Navigate } from "react-router-dom"; import { Task, TaskStatus } from "@/shared/types"; import { mockSolutions } from "@/shared/mocks/mocks"; // Keep mocks for solutions for now import CompetitionHeader from "./components/CompetitionHeader"; import TaskContent from "./components/TaskContent"; import TaskSolution from "./modules/TaskSolution"; import { getCompetitionTasks } from "@/shared/api/session"; import { Loader2 } from "lucide-react"; const CompetitionSession = () => { const { id, taskId } = useParams<{ id: string; taskId?: string }>(); const [tasks, setTasks] = useState([]); const [answer, setAnswer] = useState(""); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const competitionId = id || ""; useEffect(() => { const fetchTasks = async () => { try { setLoading(true); const fetchedTasks = await getCompetitionTasks(competitionId); setTasks(fetchedTasks); setError(null); } catch (err) { console.error("Failed to fetch tasks:", err); setError("Не удалось загрузить задания. Пожалуйста, попробуйте позже."); } finally { setLoading(false); } }; if (competitionId) { fetchTasks(); } }, [competitionId]); const currentTask = tasks.find((t) => t.id === taskId) || null; if (!taskId && tasks.length > 0 && !loading) { return ( ); } const handleSubmit = async () => { if (!currentTask || !competitionId) return; try { console.log("Solution submitted successfully"); } catch (err) { console.error("Failed to submit solution:", err); } }; return (
{loading ? (

Загрузка заданий...

) : error ? (

{error}

) : currentTask ? (
) : (

Задание не найдено

)}
); }; export default CompetitionSession;