mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 00:27:11 +00:00
continued working on session fetch
This commit is contained in:
+57
-57
@@ -1,63 +1,63 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Task } from "@/shared/types";
|
||||
import { Settings, Plus } from 'lucide-react';
|
||||
import { Button } from "@/components/ui/button";
|
||||
// import React from 'react';
|
||||
// import { Link } from 'react-router-dom';
|
||||
// import { Task } from "@/shared/types";
|
||||
// import { Settings, Plus } from 'lucide-react';
|
||||
// import { Button } from "@/components/ui/button";
|
||||
|
||||
interface ConstructorHeaderProps {
|
||||
title: string;
|
||||
tasks: Task[];
|
||||
competitionId: string;
|
||||
onAddTaskClick: () => void;
|
||||
}
|
||||
// interface ConstructorHeaderProps {
|
||||
// title: string;
|
||||
// tasks: Task[];
|
||||
// competitionId: string;
|
||||
// onAddTaskClick: () => void;
|
||||
// }
|
||||
|
||||
const ConstructorHeader: React.FC<ConstructorHeaderProps> = ({
|
||||
title,
|
||||
tasks,
|
||||
competitionId,
|
||||
onAddTaskClick
|
||||
}) => {
|
||||
return (
|
||||
<header className="bg-white shadow-sm sticky top-0 z-30 w-full">
|
||||
<div className="mx-auto max-w-6xl px-4">
|
||||
<div className="py-4 text-center">
|
||||
<h1 className="font-hse-sans text-xl font-semibold">
|
||||
{title}
|
||||
</h1>
|
||||
</div>
|
||||
// const ConstructorHeader: React.FC<ConstructorHeaderProps> = ({
|
||||
// title,
|
||||
// tasks,
|
||||
// competitionId,
|
||||
// onAddTaskClick
|
||||
// }) => {
|
||||
// return (
|
||||
// <header className="bg-white shadow-sm sticky top-0 z-30 w-full">
|
||||
// <div className="mx-auto max-w-6xl px-4">
|
||||
// <div className="py-4 text-center">
|
||||
// <h1 className="font-hse-sans text-xl font-semibold">
|
||||
// {title}
|
||||
// </h1>
|
||||
// </div>
|
||||
|
||||
<div className="flex items-center justify-center gap-4 pb-4 overflow-x-auto no-scrollbar">
|
||||
<Link
|
||||
to={`/constructor/${competitionId}/tasks/settings`}
|
||||
className="bg-gray-100 text-gray-700 rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
||||
transition-all hover:bg-gray-200 flex-shrink-0 flex items-center"
|
||||
>
|
||||
<Settings size={16} className="mr-1" />
|
||||
</Link>
|
||||
// <div className="flex items-center justify-center gap-4 pb-4 overflow-x-auto no-scrollbar">
|
||||
// <Link
|
||||
// to={`/constructor/${competitionId}/tasks/settings`}
|
||||
// className="bg-gray-100 text-gray-700 rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
||||
// transition-all hover:bg-gray-200 flex-shrink-0 flex items-center"
|
||||
// >
|
||||
// <Settings size={16} className="mr-1" />
|
||||
// </Link>
|
||||
|
||||
{tasks.map((task) => (
|
||||
<Link
|
||||
key={task.id}
|
||||
to={`/constructor/${competitionId}/tasks/${task.id}`}
|
||||
className="bg-blue-100 text-blue-700 rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
||||
transition-all hover:bg-blue-200 flex-shrink-0"
|
||||
>
|
||||
{task.number}
|
||||
</Link>
|
||||
))}
|
||||
// {tasks.map((task) => (
|
||||
// <Link
|
||||
// key={task.id}
|
||||
// to={`/constructor/${competitionId}/tasks/${task.id}`}
|
||||
// className="bg-blue-100 text-blue-700 rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
||||
// transition-all hover:bg-blue-200 flex-shrink-0"
|
||||
// >
|
||||
// {task.number}
|
||||
// </Link>
|
||||
// ))}
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="rounded-lg flex items-center px-2 h-8"
|
||||
onClick={onAddTaskClick}
|
||||
>
|
||||
<Plus size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
// <Button
|
||||
// variant="ghost"
|
||||
// size="sm"
|
||||
// className="rounded-lg flex items-center px-2 h-8"
|
||||
// onClick={onAddTaskClick}
|
||||
// >
|
||||
// <Plus size={18} />
|
||||
// </Button>
|
||||
// </div>
|
||||
// </div>
|
||||
// </header>
|
||||
// );
|
||||
// };
|
||||
|
||||
export default ConstructorHeader;
|
||||
// export default ConstructorHeader;
|
||||
@@ -1,89 +1,89 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, Navigate, useNavigate } from "react-router-dom";
|
||||
import { Task, TaskStatus } from "@/shared/types";
|
||||
import ConstructorHeader from "./components/ConstructorHeader";
|
||||
import TaskCreationModal from "./modules/TaskCreationModal";
|
||||
// import { useState } from "react";
|
||||
// import { useParams, Navigate, useNavigate } from "react-router-dom";
|
||||
// import { Task, TaskStatus } from "@/shared/types";
|
||||
// import ConstructorHeader from "./components/ConstructorHeader";
|
||||
// import TaskCreationModal from "./modules/TaskCreationModal";
|
||||
|
||||
const CompetitionConstructor = () => {
|
||||
const { id, taskId } = useParams<{ id: string; taskId?: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [competitionTitle, setCompetitionTitle] = useState("Новая олимпиада");
|
||||
const [tasks, setTasks] = useState<Task[]>([]);
|
||||
const [isTaskModalOpen, setIsTaskModalOpen] = useState(false);
|
||||
// const CompetitionConstructor = () => {
|
||||
// const { id, taskId } = useParams<{ id: string; taskId?: string }>();
|
||||
// const navigate = useNavigate();
|
||||
// const [competitionTitle, setCompetitionTitle] = useState("Новая олимпиада");
|
||||
// const [tasks, setTasks] = useState<Task[]>([]);
|
||||
// const [isTaskModalOpen, setIsTaskModalOpen] = useState(false);
|
||||
|
||||
const isSettings = taskId === "settings";
|
||||
// const isSettings = taskId === "settings";
|
||||
|
||||
const handleOpenTaskModal = () => {
|
||||
setIsTaskModalOpen(true);
|
||||
};
|
||||
// const handleOpenTaskModal = () => {
|
||||
// setIsTaskModalOpen(true);
|
||||
// };
|
||||
|
||||
const handleCloseTaskModal = () => {
|
||||
setIsTaskModalOpen(false);
|
||||
};
|
||||
// const handleCloseTaskModal = () => {
|
||||
// setIsTaskModalOpen(false);
|
||||
// };
|
||||
|
||||
const handleCreateTask = (taskData: Partial<Task>) => {
|
||||
const newTask: Task = {
|
||||
id: `task-${Date.now()}`,
|
||||
number: taskData.number || `${tasks.length + 1}`,
|
||||
status: TaskStatus.Uncleared,
|
||||
solutionType: taskData.solutionType || "input",
|
||||
description: taskData.description || "",
|
||||
requirements: taskData.requirements,
|
||||
attachments: taskData.attachments || []
|
||||
};
|
||||
// const handleCreateTask = (taskData: Partial<Task>) => {
|
||||
// const newTask: Task = {
|
||||
// id: `task-${Date.now()}`,
|
||||
// number: taskData.number || `${tasks.length + 1}`,
|
||||
// status: TaskStatus.Uncleared,
|
||||
// solutionType: taskData.solutionType || "input",
|
||||
// description: taskData.description || "",
|
||||
// requirements: taskData.requirements,
|
||||
// attachments: taskData.attachments || []
|
||||
// };
|
||||
|
||||
setTasks([...tasks, newTask]);
|
||||
setIsTaskModalOpen(false);
|
||||
navigate(`/constructor/${id}/tasks/${newTask.id}`);
|
||||
};
|
||||
// setTasks([...tasks, newTask]);
|
||||
// setIsTaskModalOpen(false);
|
||||
// navigate(`/constructor/${id}/tasks/${newTask.id}`);
|
||||
// };
|
||||
|
||||
if (!taskId) {
|
||||
if (tasks.length > 0) {
|
||||
return <Navigate to={`/constructor/${id}/tasks/${tasks[0].id}`} replace />;
|
||||
} else {
|
||||
return <Navigate to={`/constructor/${id}/tasks/settings`} replace />;
|
||||
}
|
||||
}
|
||||
// if (!taskId) {
|
||||
// if (tasks.length > 0) {
|
||||
// return <Navigate to={`/constructor/${id}/tasks/${tasks[0].id}`} replace />;
|
||||
// } else {
|
||||
// return <Navigate to={`/constructor/${id}/tasks/settings`} replace />;
|
||||
// }
|
||||
// }
|
||||
|
||||
return (
|
||||
<div className="flex flex-col min-h-screen">
|
||||
<ConstructorHeader
|
||||
title={competitionTitle}
|
||||
tasks={tasks}
|
||||
competitionId={id || ""}
|
||||
onAddTaskClick={handleOpenTaskModal}
|
||||
/>
|
||||
// return (
|
||||
// <div className="flex flex-col min-h-screen">
|
||||
// <ConstructorHeader
|
||||
// title={competitionTitle}
|
||||
// tasks={tasks}
|
||||
// competitionId={id || ""}
|
||||
// onAddTaskClick={handleOpenTaskModal}
|
||||
// />
|
||||
|
||||
<TaskCreationModal
|
||||
isOpen={isTaskModalOpen}
|
||||
onClose={handleCloseTaskModal}
|
||||
onCreateTask={handleCreateTask}
|
||||
taskCount={tasks.length}
|
||||
/>
|
||||
// <TaskCreationModal
|
||||
// isOpen={isTaskModalOpen}
|
||||
// onClose={handleCloseTaskModal}
|
||||
// onCreateTask={handleCreateTask}
|
||||
// taskCount={tasks.length}
|
||||
// />
|
||||
|
||||
<main className="flex-1 bg-[#F8F8F8] pb-8">
|
||||
<div className="max-w-6xl mx-auto px-4 py-6">
|
||||
{isSettings ? (
|
||||
<div className="bg-white rounded-lg p-6 shadow-sm">
|
||||
<h2 className="text-2xl font-semibold mb-6 font-hse-sans">Настройки олимпиады</h2>
|
||||
<p className="text-gray-500 font-hse-sans">
|
||||
Здесь будет форма настроек олимпиады
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-white rounded-lg p-6 shadow-sm">
|
||||
<h2 className="text-2xl font-semibold mb-6 font-hse-sans">
|
||||
{`Редактирование задачи ${tasks.find(t => t.id === taskId)?.number || ""}`}
|
||||
</h2>
|
||||
<p className="text-gray-500 font-hse-sans">
|
||||
Здесь будет форма редактирования задачи
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
// <main className="flex-1 bg-[#F8F8F8] pb-8">
|
||||
// <div className="max-w-6xl mx-auto px-4 py-6">
|
||||
// {isSettings ? (
|
||||
// <div className="bg-white rounded-lg p-6 shadow-sm">
|
||||
// <h2 className="text-2xl font-semibold mb-6 font-hse-sans">Настройки олимпиады</h2>
|
||||
// <p className="text-gray-500 font-hse-sans">
|
||||
// Здесь будет форма настроек олимпиады
|
||||
// </p>
|
||||
// </div>
|
||||
// ) : (
|
||||
// <div className="bg-white rounded-lg p-6 shadow-sm">
|
||||
// <h2 className="text-2xl font-semibold mb-6 font-hse-sans">
|
||||
// {`Редактирование задачи ${tasks.find(t => t.id === taskId)?.number || ""}`}
|
||||
// </h2>
|
||||
// <p className="text-gray-500 font-hse-sans">
|
||||
// Здесь будет форма редактирования задачи
|
||||
// </p>
|
||||
// </div>
|
||||
// )}
|
||||
// </div>
|
||||
// </main>
|
||||
// </div>
|
||||
// );
|
||||
// };
|
||||
|
||||
export default CompetitionConstructor;
|
||||
// export default CompetitionConstructor;
|
||||
+88
-88
@@ -1,101 +1,101 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Task } from "@/shared/types";
|
||||
import TaskNumberField from './components/TaskNumberField';
|
||||
import TaskDescriptionField from './components/TaskDescriptionField';
|
||||
import TaskRequirementsField from './components/TaskRequirementsField';
|
||||
import TaskSolutionTypeSelector from './components/TaskSolutionTypeSelector';
|
||||
import TaskFileAttachments from './components/TaskFileAttachments';
|
||||
// import React, { useState } from 'react';
|
||||
// import {
|
||||
// Dialog,
|
||||
// DialogContent,
|
||||
// DialogHeader,
|
||||
// DialogTitle,
|
||||
// DialogFooter
|
||||
// } from "@/components/ui/dialog";
|
||||
// import { Button } from "@/components/ui/button";
|
||||
// import { Task } from "@/shared/types";
|
||||
// import TaskNumberField from './components/TaskNumberField';
|
||||
// import TaskDescriptionField from './components/TaskDescriptionField';
|
||||
// import TaskRequirementsField from './components/TaskRequirementsField';
|
||||
// import TaskSolutionTypeSelector from './components/TaskSolutionTypeSelector';
|
||||
// import TaskFileAttachments from './components/TaskFileAttachments';
|
||||
|
||||
interface TaskCreationModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
onCreateTask: (task: Partial<Task>) => void;
|
||||
taskCount: number;
|
||||
}
|
||||
// interface TaskCreationModalProps {
|
||||
// isOpen: boolean;
|
||||
// onClose: () => void;
|
||||
// onCreateTask: (task: Partial<Task>) => void;
|
||||
// taskCount: number;
|
||||
// }
|
||||
|
||||
const TaskCreationModal: React.FC<TaskCreationModalProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
onCreateTask,
|
||||
taskCount
|
||||
}) => {
|
||||
const [number, setNumber] = useState(`${taskCount + 1}`);
|
||||
const [description, setDescription] = useState('');
|
||||
const [requirements, setRequirements] = useState('');
|
||||
const [solutionType, setSolutionType] = useState<'input' | 'file' | 'code'>('input');
|
||||
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
||||
// const TaskCreationModal: React.FC<TaskCreationModalProps> = ({
|
||||
// isOpen,
|
||||
// onClose,
|
||||
// onCreateTask,
|
||||
// taskCount
|
||||
// }) => {
|
||||
// const [number, setNumber] = useState(`${taskCount + 1}`);
|
||||
// const [description, setDescription] = useState('');
|
||||
// const [requirements, setRequirements] = useState('');
|
||||
// const [solutionType, setSolutionType] = useState<'input' | 'file' | 'code'>('input');
|
||||
// const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
||||
|
||||
const handleSubmit = () => {
|
||||
const newTask: Partial<Task> = {
|
||||
number,
|
||||
description,
|
||||
requirements: requirements || undefined,
|
||||
solutionType,
|
||||
attachments: attachedFiles.map(file => file.name)
|
||||
};
|
||||
// const handleSubmit = () => {
|
||||
// const newTask: Partial<Task> = {
|
||||
// number,
|
||||
// description,
|
||||
// requirements: requirements || undefined,
|
||||
// solutionType,
|
||||
// attachments: attachedFiles.map(file => file.name)
|
||||
// };
|
||||
|
||||
onCreateTask(newTask);
|
||||
// onCreateTask(newTask);
|
||||
|
||||
setNumber(`${taskCount + 1}`);
|
||||
setDescription('');
|
||||
setRequirements('');
|
||||
setSolutionType('input');
|
||||
setAttachedFiles([]);
|
||||
};
|
||||
// setNumber(`${taskCount + 1}`);
|
||||
// setDescription('');
|
||||
// setRequirements('');
|
||||
// setSolutionType('input');
|
||||
// setAttachedFiles([]);
|
||||
// };
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||
<DialogContent className="sm:max-w-[600px] font-hse-sans">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-xl">Создание новой задачи</DialogTitle>
|
||||
</DialogHeader>
|
||||
// return (
|
||||
// <Dialog open={isOpen} onOpenChange={onClose}>
|
||||
// <DialogContent className="sm:max-w-[600px] font-hse-sans">
|
||||
// <DialogHeader>
|
||||
// <DialogTitle className="text-xl">Создание новой задачи</DialogTitle>
|
||||
// </DialogHeader>
|
||||
|
||||
<div className="grid gap-4 py-4">
|
||||
<TaskNumberField
|
||||
number={number}
|
||||
onChange={setNumber}
|
||||
/>
|
||||
// <div className="grid gap-4 py-4">
|
||||
// <TaskNumberField
|
||||
// number={number}
|
||||
// onChange={setNumber}
|
||||
// />
|
||||
|
||||
<TaskDescriptionField
|
||||
description={description}
|
||||
onChange={setDescription}
|
||||
/>
|
||||
// <TaskDescriptionField
|
||||
// description={description}
|
||||
// onChange={setDescription}
|
||||
// />
|
||||
|
||||
<TaskRequirementsField
|
||||
requirements={requirements}
|
||||
onChange={setRequirements}
|
||||
/>
|
||||
// <TaskRequirementsField
|
||||
// requirements={requirements}
|
||||
// onChange={setRequirements}
|
||||
// />
|
||||
|
||||
<TaskSolutionTypeSelector
|
||||
solutionType={solutionType}
|
||||
onChange={setSolutionType}
|
||||
/>
|
||||
// <TaskSolutionTypeSelector
|
||||
// solutionType={solutionType}
|
||||
// onChange={setSolutionType}
|
||||
// />
|
||||
|
||||
<TaskFileAttachments
|
||||
files={attachedFiles}
|
||||
onChange={setAttachedFiles}
|
||||
/>
|
||||
</div>
|
||||
// <TaskFileAttachments
|
||||
// files={attachedFiles}
|
||||
// onChange={setAttachedFiles}
|
||||
// />
|
||||
// </div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={onClose}>
|
||||
Отмена
|
||||
</Button>
|
||||
<Button type="button" onClick={handleSubmit}>
|
||||
Создать задачу
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
// <DialogFooter>
|
||||
// <Button type="button" variant="outline" onClick={onClose}>
|
||||
// Отмена
|
||||
// </Button>
|
||||
// <Button type="button" onClick={handleSubmit}>
|
||||
// Создать задачу
|
||||
// </Button>
|
||||
// </DialogFooter>
|
||||
// </DialogContent>
|
||||
// </Dialog>
|
||||
// );
|
||||
// };
|
||||
|
||||
export default TaskCreationModal;
|
||||
// export default TaskCreationModal;
|
||||
@@ -3,20 +3,34 @@ import ReactMarkdown from 'react-markdown';
|
||||
import remarkMath from 'remark-math';
|
||||
import rehypeKatex from 'rehype-katex';
|
||||
import 'katex/dist/katex.min.css';
|
||||
import { Task } from "@/shared/types";
|
||||
import { Task } from '@/shared/types/task';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { getTaskAttachments } from '@/shared/api/session';
|
||||
import { FileIcon, Loader2 } from 'lucide-react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
interface TaskContentProps {
|
||||
task: Task;
|
||||
}
|
||||
|
||||
const TaskContent: React.FC<TaskContentProps> = ({ task }) => {
|
||||
const { id: competitionId } = useParams<{ id: string }>();
|
||||
|
||||
const attachmentsQuery = useQuery({
|
||||
queryKey: ['taskAttachments', competitionId, task.id],
|
||||
queryFn: () => getTaskAttachments(competitionId || '', task.id),
|
||||
enabled: !!(competitionId && task.id),
|
||||
});
|
||||
|
||||
const attachments = attachmentsQuery.data || [];
|
||||
|
||||
return (
|
||||
<div className="flex-1 bg-white rounded-lg p-6">
|
||||
<h2 className="text-3xl font-semibold mb-6 font-hse-sans">
|
||||
Задача {task.number}
|
||||
Задача {task.in_competition_position}
|
||||
</h2>
|
||||
|
||||
<div className="prose prose-lg max-w-none text-gray-700 font-hse-sans">
|
||||
<div className="prose prose-lg max-w-none text-gray-700 font-hse-sans mb-6">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkMath]}
|
||||
rehypePlugins={[rehypeKatex]}
|
||||
@@ -24,8 +38,43 @@ const TaskContent: React.FC<TaskContentProps> = ({ task }) => {
|
||||
{task.description}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
|
||||
{attachmentsQuery.isLoading ? (
|
||||
<div className="flex items-center justify-center py-4">
|
||||
<Loader2 className="h-5 w-5 animate-spin text-gray-400 mr-2" />
|
||||
<span className="text-gray-500 font-hse-sans">Загрузка файлов...</span>
|
||||
</div>
|
||||
) : attachments.length > 0 ? (
|
||||
<div className="mt-6">
|
||||
<h3 className="text-lg font-semibold mb-3 font-hse-sans">Прикрепленные файлы</h3>
|
||||
<div className="flex flex-col gap-2">
|
||||
{attachments.map((attachment) => (
|
||||
<a
|
||||
key={attachment.id}
|
||||
href={attachment.file}
|
||||
download
|
||||
className="flex items-center p-3 border rounded-md hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
<FileIcon size={18} className="text-blue-500 mr-2" />
|
||||
<span className="font-hse-sans">
|
||||
{getFileNameFromUrl(attachment.file)}
|
||||
</span>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TaskContent;
|
||||
const getFileNameFromUrl = (url: string): string => {
|
||||
try {
|
||||
const parts = url.split('/');
|
||||
return parts[parts.length - 1];
|
||||
} catch (e) {
|
||||
return 'Файл';
|
||||
}
|
||||
};
|
||||
|
||||
export default TaskContent;
|
||||
@@ -1,23 +1,32 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, Navigate } from "react-router-dom";
|
||||
import { mockSolutions } from "@/shared/mocks/mocks";
|
||||
import CompetitionHeader from "./components/CompetitionHeader";
|
||||
import TaskContent from "./components/TaskContent";
|
||||
import TaskSolution from "./modules/TaskSolution";
|
||||
import { getCompetitionTasks } from "@/shared/api/session";
|
||||
import { getCompetitionTasks, submitTaskSolution } from "@/shared/api/session";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
const CompetitionSession = () => {
|
||||
const { id, taskId } = useParams<{ id: string; taskId?: string }>();
|
||||
const [answer, setAnswer] = useState("");
|
||||
const competitionId = id || "";
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const tasksQuery = useQuery({
|
||||
queryKey: ["competitionTasks", competitionId],
|
||||
queryFn: () => getCompetitionTasks(competitionId),
|
||||
enabled: !!competitionId,
|
||||
// refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
const submitMutation = useMutation({
|
||||
mutationFn: () => submitTaskSolution(competitionId, taskId || "", answer),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['submissionHistory', competitionId, taskId]
|
||||
});
|
||||
setAnswer("");
|
||||
}
|
||||
});
|
||||
|
||||
const tasks = tasksQuery.data || [];
|
||||
@@ -35,14 +44,9 @@ const CompetitionSession = () => {
|
||||
);
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!currentTask || !competitionId) return;
|
||||
|
||||
try {
|
||||
console.log("Solution submitted successfully");
|
||||
} catch (err) {
|
||||
console.error("Failed to submit solution:", err);
|
||||
}
|
||||
const handleSubmit = () => {
|
||||
if (!currentTask || !competitionId || !answer.trim()) return;
|
||||
submitMutation.mutate();
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -69,7 +73,7 @@ const CompetitionSession = () => {
|
||||
<TaskContent task={currentTask} />
|
||||
<TaskSolution
|
||||
task={currentTask}
|
||||
solutions={mockSolutions}
|
||||
solutions={[]}
|
||||
answer={answer}
|
||||
setAnswer={setAnswer}
|
||||
onSubmit={handleSubmit}
|
||||
|
||||
+18
-35
@@ -1,48 +1,31 @@
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
import { Button } from "@/components/ui/button";
|
||||
import SolutionHistorySheet from '../SolutionHistorySheet';
|
||||
import { Solution } from "@/shared/types";
|
||||
import { mockSolutions } from '@/shared/mocks/mocks';
|
||||
|
||||
interface ActionButtonsProps {
|
||||
onSubmit: () => void;
|
||||
solutionHistory?: Solution[];
|
||||
onHistoryClick: () => void;
|
||||
}
|
||||
|
||||
const ActionButtons: React.FC<ActionButtonsProps> = ({
|
||||
onSubmit,
|
||||
solutionHistory = mockSolutions
|
||||
onHistoryClick
|
||||
}) => {
|
||||
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
||||
|
||||
const handleHistoryClick = () => {
|
||||
setIsHistoryOpen(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex gap-8">
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="font-hse-sans bg-white hover:bg-gray-100"
|
||||
onClick={handleHistoryClick}
|
||||
>
|
||||
История
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onSubmit}
|
||||
className="font-hse-sans flex-grow"
|
||||
>
|
||||
Отправить решение
|
||||
</Button>
|
||||
</div>
|
||||
{/* чуть-чуть рак */}
|
||||
<SolutionHistorySheet
|
||||
isOpen={isHistoryOpen}
|
||||
onOpenChange={setIsHistoryOpen}
|
||||
solutions={solutionHistory}
|
||||
/>
|
||||
</>
|
||||
<div className="flex gap-8">
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="font-hse-sans bg-white hover:bg-gray-100"
|
||||
onClick={onHistoryClick}
|
||||
>
|
||||
История
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onSubmit}
|
||||
className="font-hse-sans flex-grow"
|
||||
>
|
||||
Отправить решение
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
+5
-3
@@ -3,18 +3,20 @@ import { Sheet, SheetClose, SheetContent, SheetHeader, SheetTitle } from "@/comp
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { X } from "lucide-react";
|
||||
import SolutionStatus from '../SolutionStatus';
|
||||
import { Solution } from "@/shared/types";
|
||||
import { Solution } from '@/shared/types/task';
|
||||
|
||||
interface SolutionHistorySheetProps {
|
||||
isOpen: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
solutions: Solution[];
|
||||
maxPoints: number
|
||||
}
|
||||
|
||||
const SolutionHistorySheet: React.FC<SolutionHistorySheetProps> = ({
|
||||
isOpen,
|
||||
onOpenChange,
|
||||
solutions
|
||||
solutions,
|
||||
maxPoints
|
||||
}) => {
|
||||
return (
|
||||
<Sheet open={isOpen} onOpenChange={onOpenChange}>
|
||||
@@ -34,7 +36,7 @@ const SolutionHistorySheet: React.FC<SolutionHistorySheetProps> = ({
|
||||
{solutions.length > 0 ? (
|
||||
solutions.map((solution, index) => (
|
||||
<div key={index} className="w-full">
|
||||
<SolutionStatus solution={solution} />
|
||||
<SolutionStatus solution={solution} maxPoints={maxPoints} />
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
|
||||
+11
-26
@@ -1,41 +1,26 @@
|
||||
import React from 'react';
|
||||
import { Solution, TaskStatus } from "@/shared/types";
|
||||
import { getTaskBgColor, getTaskTextColor } from '@/pages/CompetitionSession/utils/utils';
|
||||
import { Solution } from '@/shared/types/task';
|
||||
import { getSolutionBgColor, getSolutionTextColor, getStatusText } from '@/pages/CompetitionSession/utils/utils';
|
||||
|
||||
interface SolutionStatusProps {
|
||||
solution: Solution;
|
||||
maxPoints: number;
|
||||
}
|
||||
|
||||
const SolutionStatus: React.FC<SolutionStatusProps> = ({ solution }) => {
|
||||
const getStatusText = (status: TaskStatus, score?: number, maxScore?: number) => {
|
||||
switch (status) {
|
||||
case TaskStatus.Checking:
|
||||
return 'На проверке';
|
||||
case TaskStatus.Wrong:
|
||||
return 'Неверный ответ';
|
||||
case TaskStatus.Correct:
|
||||
return `Зачтено ${maxScore}/${maxScore} баллов`;
|
||||
case TaskStatus.Partial:
|
||||
return `Зачтено ${score}/${maxScore} баллов`;
|
||||
case TaskStatus.Uncleared:
|
||||
return 'Не решено';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const SolutionStatus: React.FC<SolutionStatusProps> = ({ solution, maxPoints }) => {
|
||||
|
||||
return (
|
||||
<div className={`${getTaskBgColor(solution.status)} rounded-lg p-4 relative`}>
|
||||
<div className={`${getSolutionBgColor(solution.status, solution.earned_points, maxPoints)} rounded-lg p-4 relative`}>
|
||||
<div className="flex flex-col">
|
||||
<span className={`${getTaskTextColor(solution.status)} font-medium`}>
|
||||
<span className={`${getSolutionTextColor(solution.status, solution.earned_points, maxPoints)} font-medium`}>
|
||||
Решение {solution.id}
|
||||
</span>
|
||||
<span className={`${getTaskTextColor(solution.status)} mt-1`}>
|
||||
{getStatusText(solution.status, solution.score, solution.maxScore)}
|
||||
<span className={`${getSolutionTextColor(solution.status, solution.earned_points, maxPoints)} mt-1`}>
|
||||
{getStatusText(solution.status, solution.earned_points, maxPoints)}
|
||||
</span>
|
||||
</div>
|
||||
<div className={`absolute bottom-2 right-3 text-xs ${getTaskTextColor(solution.status)}`}>
|
||||
{solution.date}
|
||||
<div className={`absolute bottom-2 right-3 text-xs ${getSolutionTextColor(solution.status, solution.earned_points, maxPoints)}`}>
|
||||
{solution.timestamp}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import React, { useState, useRef } from 'react';
|
||||
import { Solution, Task } from "@/shared/types";
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { Task, TaskType, Solution } from '@/shared/types/task';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { getTaskSolutionHistory } from '@/shared/api/session';
|
||||
import SolutionStatus from './components/SolutionStatus';
|
||||
import InputSolution from './components/InputSolution';
|
||||
import FileSolution from './components/FileSolution';
|
||||
import CodeSolution from './components/CodeSolution';
|
||||
import ActionButtons from './components/ActionButtons';
|
||||
import SolutionHistorySheet from './components/SolutionHistorySheet';
|
||||
|
||||
interface TaskSolutionProps {
|
||||
task: Task;
|
||||
@@ -12,7 +16,6 @@ interface TaskSolutionProps {
|
||||
answer: string;
|
||||
setAnswer: (value: string) => void;
|
||||
onSubmit: () => void;
|
||||
|
||||
}
|
||||
|
||||
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
@@ -24,16 +27,30 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
}) => {
|
||||
const [selectedFile, setSelectedFile] = useState<File | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
||||
const { id: competitionId } = useParams<{ id: string }>();
|
||||
|
||||
const solutionsQuery = useQuery({
|
||||
queryKey: ['solutionHistory', competitionId, task.id],
|
||||
queryFn: () => getTaskSolutionHistory(competitionId || '', task.id),
|
||||
enabled: !!(competitionId && task.id),
|
||||
});
|
||||
|
||||
const solutionHistory = solutionsQuery.data || [];
|
||||
|
||||
const handleOpenHistory = () => {
|
||||
setIsHistoryOpen(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="md:w-[500px] flex flex-col gap-4">
|
||||
<SolutionStatus solution={solutions[0]} />
|
||||
<SolutionStatus solution={solutions[0]} maxPoints={task.points}/>
|
||||
|
||||
{task.solutionType === 'input' && (
|
||||
{task.type === TaskType.INPUT && (
|
||||
<InputSolution answer={answer} setAnswer={setAnswer} />
|
||||
)}
|
||||
|
||||
{task.solutionType === 'file' && (
|
||||
{task.type === TaskType.FILE && (
|
||||
<FileSolution
|
||||
selectedFile={selectedFile}
|
||||
setSelectedFile={setSelectedFile}
|
||||
@@ -41,11 +58,21 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
/>
|
||||
)}
|
||||
|
||||
{task.solutionType === 'code' && (
|
||||
{task.type === TaskType.CODE && (
|
||||
<CodeSolution answer={answer} setAnswer={setAnswer} />
|
||||
)}
|
||||
|
||||
<ActionButtons onSubmit={onSubmit} />
|
||||
<ActionButtons
|
||||
onSubmit={onSubmit}
|
||||
onHistoryClick={handleOpenHistory}
|
||||
/>
|
||||
|
||||
<SolutionHistorySheet
|
||||
isOpen={isHistoryOpen}
|
||||
onOpenChange={setIsHistoryOpen}
|
||||
solutions={solutionHistory}
|
||||
maxPoints={task.points}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { TaskStatus } from "@/shared/types";
|
||||
import { SolutionStatus } from "@/shared/types/task";
|
||||
const getTaskBgColor = (status: TaskStatus): string => {
|
||||
switch (status) {
|
||||
case TaskStatus.Uncleared: return "bg-[var(--color-task-uncleared)]";
|
||||
@@ -19,4 +20,39 @@ const getTaskTextColor = (status: TaskStatus): string => {
|
||||
}
|
||||
};
|
||||
|
||||
export {getTaskBgColor, getTaskTextColor}
|
||||
const getSolutionBgColor = (status: SolutionStatus, earned_points: number, maxPoints: number): string => {
|
||||
switch (status) {
|
||||
case SolutionStatus.SENT: return "text-[var(--color-task-uncleared)]";
|
||||
case SolutionStatus.CHECKING: return "text-[var(--color-task-checking)]";
|
||||
case SolutionStatus.CHECKED: {
|
||||
if (earned_points === 0) return "text-[var(--color-task-wrong)]";
|
||||
else if (earned_points === maxPoints) "text-[var(--color-task-correct)]";
|
||||
return "text-[var(--color-task-partial)]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getSolutionTextColor = (status: SolutionStatus, earned_points: number, maxPoints: number): string => {
|
||||
switch (status) {
|
||||
case SolutionStatus.SENT: return "text-[var(--color-task-text-uncleared)]";
|
||||
case SolutionStatus.CHECKING: return "text-[var(--color-task-text-checking)]";
|
||||
case SolutionStatus.CHECKED: {
|
||||
if (earned_points === 0) return "text-[var(--color-task-text-wrong)]";
|
||||
else if (earned_points === maxPoints) "text-[var(--color-task-text-correct)]";
|
||||
return "text-[var(--color-task-text-partial)]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusText = (status: SolutionStatus, earned_points: number, maxPoints: number): string => {
|
||||
switch (status) {
|
||||
case SolutionStatus.SENT: return "Решение отправлено";
|
||||
case SolutionStatus.CHECKING: return "Решение проверяется";
|
||||
case SolutionStatus.CHECKED: {
|
||||
if (earned_points === 0) return "Неверный ответ";
|
||||
else if (earned_points === maxPoints) `Зачтено ${maxPoints}/${maxPoints} баллов`;
|
||||
return `Зачтено ${earned_points}/${maxPoints} баллов`;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {getTaskBgColor, getTaskTextColor, getSolutionBgColor, getSolutionTextColor, getStatusText}
|
||||
@@ -1,10 +1,19 @@
|
||||
import { userFetch } from ".";
|
||||
import { Task } from "../types/task";
|
||||
import { Task, Solution, TaskAttachment } from "../types/task";
|
||||
|
||||
export const getCompetitionTasks = async (competitionId: string) => {
|
||||
return await userFetch<Task[]>(`/competitions/${competitionId}/tasks`);
|
||||
};
|
||||
|
||||
export const getTaskSolutionHistory = async (competitionId: string, taskId: string) => {
|
||||
return await userFetch<Solution[]>(`/competitions/${competitionId}/tasks/${taskId}/history`);
|
||||
};
|
||||
|
||||
export const getTaskAttachments = async (competitionId: string, taskId: string) => {
|
||||
return await userFetch<TaskAttachment[]>(`/competitions/${competitionId}/tasks/${taskId}/attachments`);
|
||||
};
|
||||
|
||||
|
||||
export const submitTaskSolution = async (
|
||||
competitionId: string,
|
||||
taskId: string,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface Task {
|
||||
interface Task {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
@@ -7,8 +7,30 @@ export interface Task {
|
||||
points: number;
|
||||
}
|
||||
|
||||
export interface TaskAttachment {
|
||||
id: string;
|
||||
file: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
enum TaskType {
|
||||
INPUT = "input",
|
||||
FILE = "file",
|
||||
CODE = "code",
|
||||
}
|
||||
|
||||
enum SolutionStatus {
|
||||
SENT = "sent",
|
||||
CHECKING = "checking",
|
||||
CHECKED = "checked",
|
||||
}
|
||||
|
||||
interface Solution {
|
||||
id: string,
|
||||
status: SolutionStatus,
|
||||
timestamp: string,
|
||||
earned_points: number
|
||||
}
|
||||
|
||||
export type {Task, Solution}
|
||||
export {TaskType, SolutionStatus}
|
||||
Reference in New Issue
Block a user