mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 19:07:10 +00:00
fix file submissions
This commit is contained in:
+53
-8
@@ -7,17 +7,23 @@ interface FileSolutionProps {
|
||||
setSelectedFile: (file: File | null) => void;
|
||||
fileInputRef: React.RefObject<HTMLInputElement>;
|
||||
existingFileUrl?: string | null;
|
||||
onClearExistingFile?: () => void; // New prop to clear existing file URL
|
||||
}
|
||||
|
||||
const FileSolution: React.FC<FileSolutionProps> = ({
|
||||
selectedFile,
|
||||
setSelectedFile,
|
||||
fileInputRef,
|
||||
existingFileUrl = null
|
||||
existingFileUrl = null,
|
||||
onClearExistingFile
|
||||
}) => {
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
if (event.target.files && event.target.files[0]) {
|
||||
setSelectedFile(event.target.files[0]);
|
||||
// Clear existing file URL when a new file is selected
|
||||
if (existingFileUrl && onClearExistingFile) {
|
||||
onClearExistingFile();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -41,9 +47,28 @@ const FileSolution: React.FC<FileSolutionProps> = ({
|
||||
|
||||
if (e.dataTransfer.files && e.dataTransfer.files[0]) {
|
||||
setSelectedFile(e.dataTransfer.files[0]);
|
||||
// Clear existing file URL when a new file is dropped
|
||||
if (existingFileUrl && onClearExistingFile) {
|
||||
onClearExistingFile();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Handle clearing the file
|
||||
const handleClearFile = () => {
|
||||
setSelectedFile(null);
|
||||
// Also clear the existing file URL if it exists
|
||||
if (existingFileUrl && onClearExistingFile) {
|
||||
onClearExistingFile();
|
||||
}
|
||||
};
|
||||
|
||||
// Handle selecting a new file when an existing file is shown
|
||||
const handleSelectNewFile = () => {
|
||||
// Just trigger the file input click - the actual clearing will happen in handleFileChange
|
||||
fileInputRef.current?.click();
|
||||
};
|
||||
|
||||
const fileName = selectedFile
|
||||
? selectedFile.name
|
||||
: existingFileUrl
|
||||
@@ -79,13 +104,33 @@ const FileSolution: React.FC<FileSolutionProps> = ({
|
||||
Скачать
|
||||
</a>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="text-blue-500 text-sm p-0 h-auto hover:bg-transparent hover:text-blue-600 font-hse-sans"
|
||||
onClick={() => setSelectedFile(null)}
|
||||
>
|
||||
{!selectedFile && existingFileUrl ? "Выбрать другой файл" : "Очистить"}
|
||||
</Button>
|
||||
|
||||
{selectedFile ? (
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="text-blue-500 text-sm p-0 h-auto hover:bg-transparent hover:text-blue-600 font-hse-sans"
|
||||
onClick={handleClearFile}
|
||||
>
|
||||
Очистить
|
||||
</Button>
|
||||
) : existingFileUrl ? (
|
||||
<div className="flex gap-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="text-blue-500 text-sm p-0 h-auto hover:bg-transparent hover:text-blue-600 font-hse-sans"
|
||||
onClick={handleSelectNewFile}
|
||||
>
|
||||
Выбрать другой файл
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="text-red-500 text-sm p-0 h-auto hover:bg-transparent hover:text-red-600 font-hse-sans"
|
||||
onClick={handleClearFile}
|
||||
>
|
||||
Очистить
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -44,15 +44,18 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
setIsHistoryOpen(true);
|
||||
};
|
||||
|
||||
const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[solutionHistory.length - 1] : null;
|
||||
const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[0] : null;
|
||||
|
||||
const handleSolutionSelect = async (solution: Solution) => {
|
||||
if (!solution.content) return;
|
||||
|
||||
setSelectedSolutionUrl(solution.content);
|
||||
|
||||
try {
|
||||
if (task.type !== TaskType.FILE) {
|
||||
if (task.type === TaskType.FILE) {
|
||||
// For file tasks, just store the URL
|
||||
setSelectedFile(null); // Clear any selected file first
|
||||
setSelectedSolutionUrl(solution.content);
|
||||
} else {
|
||||
// For INPUT and CODE tasks, fetch the content and set as answer
|
||||
const response = await fetch(solution.content);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch solution content: ${response.status}`);
|
||||
@@ -65,6 +68,11 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// Function to clear the existing file URL
|
||||
const handleClearExistingFile = () => {
|
||||
setSelectedSolutionUrl(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="md:w-[500px] flex flex-col gap-4">
|
||||
{latestSolution ? (
|
||||
@@ -85,6 +93,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
setSelectedFile={setSelectedFile}
|
||||
fileInputRef={fileInputRef}
|
||||
existingFileUrl={selectedSolutionUrl}
|
||||
onClearExistingFile={handleClearExistingFile}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user