mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 12:07:10 +00:00
fix: status change
This commit is contained in:
+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>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ interface TaskSolutionProps {
|
|||||||
selectedFile: File | null;
|
selectedFile: File | null;
|
||||||
setSelectedFile: (file: File | null) => void;
|
setSelectedFile: (file: File | null) => void;
|
||||||
onSubmit: () => void;
|
onSubmit: () => void;
|
||||||
|
isSubmitting?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||||
@@ -30,6 +31,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 solutionsQuery = useQuery({
|
const solutionsQuery = useQuery({
|
||||||
@@ -39,18 +41,40 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const solutionHistory = solutionsQuery.data || [];
|
const solutionHistory = solutionsQuery.data || [];
|
||||||
const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[0] : null;
|
|
||||||
|
const getLatestSolution = () => {
|
||||||
|
return solutionHistory.length > 0 ? solutionHistory[solutionHistory.length - 1] : null;
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadLatestSolution = async () => {
|
if (solutionHistory.length > 0 && !currentSolution) {
|
||||||
if (!latestSolution || !latestSolution.content) return;
|
setCurrentSolution(getLatestSolution());
|
||||||
|
}
|
||||||
|
}, [solutionHistory, currentSolution]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const latestSolution = getLatestSolution();
|
||||||
|
if (solutionHistory.length > 0 && currentSolution && latestSolution &&
|
||||||
|
latestSolution.id !== currentSolution.id) {
|
||||||
|
setCurrentSolution(latestSolution);
|
||||||
|
}
|
||||||
|
}, [solutionHistory, currentSolution]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentSolution(null);
|
||||||
|
setSelectedSolutionUrl(null);
|
||||||
|
}, [task.id]);
|
||||||
|
|
||||||
|
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) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to fetch solution content: ${response.status}`);
|
throw new Error(`Failed to fetch solution content: ${response.status}`);
|
||||||
}
|
}
|
||||||
@@ -58,38 +82,20 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
setAnswer(text);
|
setAnswer(text);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading latest solution content:', error);
|
console.error('Error loading solution content:', error);
|
||||||
} finally {
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (latestSolution && !solutionsQuery.isLoading && !solutionsQuery.isError) {
|
loadSolutionContent();
|
||||||
loadLatestSolution();
|
}, [currentSolution, task.type, setAnswer, setSelectedFile]);
|
||||||
}
|
|
||||||
}, [latestSolution, task.id, task.type, setAnswer, setSelectedFile]);
|
|
||||||
|
|
||||||
const handleOpenHistory = () => {
|
const handleOpenHistory = () => {
|
||||||
setIsHistoryOpen(true);
|
setIsHistoryOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSolutionSelect = async (solution: Solution) => {
|
const handleSolutionSelect = (solution: Solution) => {
|
||||||
if (!solution.content) return;
|
setCurrentSolution(solution);
|
||||||
|
setIsHistoryOpen(false);
|
||||||
try {
|
|
||||||
if (task.type === TaskType.FILE) {
|
|
||||||
setSelectedFile(null);
|
|
||||||
setSelectedSolutionUrl(solution.content);
|
|
||||||
} else {
|
|
||||||
const response = await fetch(solution.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 solution content:', error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClearExistingFile = () => {
|
const handleClearExistingFile = () => {
|
||||||
@@ -98,8 +104,8 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
|
|
||||||
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 +147,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