continued working on session fetch

This commit is contained in:
rngsurrounded
2025-03-02 22:28:57 +09:00
parent 50c808671a
commit 7de03ecf86
12 changed files with 431 additions and 314 deletions
@@ -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>
);
};