mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 03:57:09 +00:00
test fix
This commit is contained in:
+10
-15
@@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Sheet, SheetClose, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet";
|
import { Sheet, SheetClose, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { X, Check } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
import SolutionStatus from '../SolutionStatus';
|
import SolutionStatus from '../SolutionStatus';
|
||||||
import { Solution } from '@/shared/types/task';
|
import { Solution, TaskType } from '@/shared/types/task';
|
||||||
|
|
||||||
interface SolutionHistorySheetProps {
|
interface SolutionHistorySheetProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -11,7 +11,6 @@ interface SolutionHistorySheetProps {
|
|||||||
solutions: Solution[];
|
solutions: Solution[];
|
||||||
maxPoints: number;
|
maxPoints: number;
|
||||||
onSolutionSelect: (solution: Solution) => void;
|
onSolutionSelect: (solution: Solution) => void;
|
||||||
currentSolutionId?: string | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SolutionHistorySheet: React.FC<SolutionHistorySheetProps> = ({
|
const SolutionHistorySheet: React.FC<SolutionHistorySheetProps> = ({
|
||||||
@@ -19,10 +18,8 @@ const SolutionHistorySheet: React.FC<SolutionHistorySheetProps> = ({
|
|||||||
onOpenChange,
|
onOpenChange,
|
||||||
solutions,
|
solutions,
|
||||||
maxPoints,
|
maxPoints,
|
||||||
onSolutionSelect,
|
onSolutionSelect
|
||||||
currentSolutionId
|
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet open={isOpen} onOpenChange={onOpenChange}>
|
<Sheet open={isOpen} onOpenChange={onOpenChange}>
|
||||||
<SheetContent className="w-[350px] sm:w-[450px] p-0">
|
<SheetContent className="w-[350px] sm:w-[450px] p-0">
|
||||||
@@ -39,17 +36,15 @@ const SolutionHistorySheet: React.FC<SolutionHistorySheetProps> = ({
|
|||||||
|
|
||||||
<div className="flex flex-col mt-3 space-y-2.5 overflow-y-auto max-h-[calc(100vh-80px)] px-4 pb-4">
|
<div className="flex flex-col mt-3 space-y-2.5 overflow-y-auto max-h-[calc(100vh-80px)] px-4 pb-4">
|
||||||
{solutions.length > 0 ? (
|
{solutions.length > 0 ? (
|
||||||
solutions.map((solution) => (
|
solutions.map((solution, index) => (
|
||||||
<div
|
<div
|
||||||
key={solution.id}
|
key={solution.id || index}
|
||||||
className={`w-full cursor-pointer relative ${solution.id === currentSolutionId ? 'ring-2 ring-blue-500 rounded-lg' : ''}`}
|
className="w-full cursor-pointer transition-transform hover:scale-[1.01]"
|
||||||
onClick={() => onSolutionSelect(solution)}
|
onClick={() => {
|
||||||
|
onSolutionSelect(solution);
|
||||||
|
onOpenChange(false);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{solution.id === currentSolutionId && (
|
|
||||||
<div className="absolute top-2 right-2 z-10 bg-blue-500 text-white rounded-full p-1">
|
|
||||||
<Check size={14} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<SolutionStatus solution={solution} maxPoints={maxPoints} />
|
<SolutionStatus solution={solution} maxPoints={maxPoints} />
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef } 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';
|
||||||
@@ -30,9 +30,7 @@ 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 taskIdRef = useRef<string | null>(null);
|
|
||||||
|
|
||||||
const solutionsQuery = useQuery({
|
const solutionsQuery = useQuery({
|
||||||
queryKey: ['solutionHistory', competitionId, task.id],
|
queryKey: ['solutionHistory', competitionId, task.id],
|
||||||
@@ -41,48 +39,24 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const solutionHistory = solutionsQuery.data || [];
|
const solutionHistory = solutionsQuery.data || [];
|
||||||
// Handle task changes
|
|
||||||
useEffect(() => {
|
|
||||||
if (taskIdRef.current !== task.id) {
|
|
||||||
setCurrentSolution(null);
|
|
||||||
setSelectedSolutionUrl(null);
|
|
||||||
setAnswer("");
|
|
||||||
setSelectedFile(null);
|
|
||||||
taskIdRef.current = task.id;
|
|
||||||
|
|
||||||
// Wait for the query to complete
|
const handleOpenHistory = () => {
|
||||||
if (!solutionsQuery.isLoading && solutionHistory.length > 0) {
|
setIsHistoryOpen(true);
|
||||||
// Get the most recent solution (last in the array)
|
};
|
||||||
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
|
||||||
setCurrentSolution(latestSolution);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [task.id, solutionHistory, solutionsQuery.isLoading, setAnswer, setSelectedFile]);
|
|
||||||
|
|
||||||
// Refresh current solution when the solution history changes (after a new submission)
|
const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[0] : null;
|
||||||
useEffect(() => {
|
|
||||||
if (!solutionsQuery.isLoading && solutionHistory.length > 0) {
|
|
||||||
// If we don't have a current solution or there's a new submission
|
|
||||||
// (which would be the last item in the array)
|
|
||||||
if (!currentSolution ||
|
|
||||||
currentSolution.id !== solutionHistory[solutionHistory.length - 1].id) {
|
|
||||||
// Set to the latest solution (last in the array)
|
|
||||||
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [solutionHistory, currentSolution, solutionsQuery.isLoading]);
|
|
||||||
|
|
||||||
// Load solution content when current solution changes
|
const handleSolutionSelect = async (solution: Solution) => {
|
||||||
useEffect(() => {
|
if (!solution.content) return;
|
||||||
const loadSolutionContent = async () => {
|
|
||||||
if (!currentSolution || !currentSolution.content) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (task.type === TaskType.FILE) {
|
if (task.type === TaskType.FILE) {
|
||||||
setSelectedFile(null);
|
// For file tasks, just store the URL
|
||||||
setSelectedSolutionUrl(currentSolution.content);
|
setSelectedFile(null); // Clear any selected file first
|
||||||
|
setSelectedSolutionUrl(solution.content);
|
||||||
} else {
|
} else {
|
||||||
const response = await fetch(currentSolution.content);
|
// For INPUT and CODE tasks, fetch the content and set as answer
|
||||||
|
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}`);
|
||||||
}
|
}
|
||||||
@@ -94,30 +68,16 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
loadSolutionContent();
|
// Function to clear the existing file URL
|
||||||
}, [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);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitWrapper = () => {
|
|
||||||
onSubmit();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="md:w-[500px] flex flex-col gap-4">
|
<div className="md:w-[500px] flex flex-col gap-4">
|
||||||
{currentSolution ? (
|
{latestSolution ? (
|
||||||
<SolutionStatus solution={currentSolution} maxPoints={task.points}/>
|
<SolutionStatus solution={latestSolution} 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">
|
||||||
Решение еще не отправлено
|
Решение еще не отправлено
|
||||||
@@ -125,10 +85,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{task.type === TaskType.INPUT && (
|
{task.type === TaskType.INPUT && (
|
||||||
<InputSolution
|
<InputSolution answer={answer} setAnswer={setAnswer} />
|
||||||
answer={answer}
|
|
||||||
setAnswer={setAnswer}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{task.type === TaskType.FILE && (
|
{task.type === TaskType.FILE && (
|
||||||
@@ -142,14 +99,11 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{task.type === TaskType.CODE && (
|
{task.type === TaskType.CODE && (
|
||||||
<CodeSolution
|
<CodeSolution answer={answer} setAnswer={setAnswer} />
|
||||||
answer={answer}
|
|
||||||
setAnswer={setAnswer}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ActionButtons
|
<ActionButtons
|
||||||
onSubmit={handleSubmitWrapper}
|
onSubmit={onSubmit}
|
||||||
onHistoryClick={handleOpenHistory}
|
onHistoryClick={handleOpenHistory}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -159,7 +113,6 @@ 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