test: history

This commit is contained in:
rngsurrounded
2025-03-03 03:15:19 +09:00
parent 17858f1e45
commit 86f68619cb
4 changed files with 67 additions and 19 deletions
@@ -29,6 +29,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
}) => {
const fileInputRef = useRef<HTMLInputElement>(null);
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
const [selectedSolutionUrl, setSelectedSolutionUrl] = useState<string | null>(null);
const { id: competitionId } = useParams<{ id: string }>();
const solutionsQuery = useQuery({
@@ -45,6 +46,25 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
const latestSolution = solutionHistory && solutionHistory.length > 0 ? solutionHistory[solutionHistory.length - 1] : null;
const handleSolutionSelect = async (solution: Solution) => {
if (!solution.content) return;
setSelectedSolutionUrl(solution.content);
try {
if (task.type !== TaskType.FILE) {
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);
}
};
return (
<div className="md:w-[500px] flex flex-col gap-4">
{latestSolution ? (
@@ -64,6 +84,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
selectedFile={selectedFile}
setSelectedFile={setSelectedFile}
fileInputRef={fileInputRef}
existingFileUrl={selectedSolutionUrl}
/>
)}
@@ -81,6 +102,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
onOpenChange={setIsHistoryOpen}
solutions={solutionHistory}
maxPoints={task.points}
onSolutionSelect={handleSolutionSelect}
/>
</div>
);