fix file submissions

This commit is contained in:
rngsurrounded
2025-03-03 05:56:40 +09:00
parent 7bbb34f574
commit 87872fbdec
3 changed files with 67 additions and 13 deletions
@@ -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}
/>
)}