mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 03:57:09 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -44,9 +44,6 @@ const CompetitionSession = () => {
|
|||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ['solutionHistory', competitionId, taskId]
|
queryKey: ['solutionHistory', competitionId, taskId]
|
||||||
});
|
});
|
||||||
|
|
||||||
setAnswer("");
|
|
||||||
setSelectedFile(null);
|
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.error("Error submitting solution:", error);
|
console.error("Error submitting solution:", error);
|
||||||
|
|||||||
+1
@@ -22,6 +22,7 @@ const SolutionHistorySheet: React.FC<SolutionHistorySheetProps> = ({
|
|||||||
onSolutionSelect,
|
onSolutionSelect,
|
||||||
currentSolutionId
|
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">
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
const [selectedSolutionUrl, setSelectedSolutionUrl] = useState<string | null>(null);
|
const [selectedSolutionUrl, setSelectedSolutionUrl] = useState<string | null>(null);
|
||||||
const [currentSolution, setCurrentSolution] = useState<Solution | null>(null);
|
const [currentSolution, setCurrentSolution] = useState<Solution | null>(null);
|
||||||
const { id: competitionId } = useParams<{ id: string }>();
|
const { id: competitionId } = useParams<{ id: string }>();
|
||||||
const previousTaskIdRef = useRef<string | null>(null);
|
const taskIdRef = useRef<string | null>(null);
|
||||||
|
|
||||||
const solutionsQuery = useQuery({
|
const solutionsQuery = useQuery({
|
||||||
queryKey: ['solutionHistory', competitionId, task.id],
|
queryKey: ['solutionHistory', competitionId, task.id],
|
||||||
@@ -40,37 +40,42 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
enabled: !!(competitionId && task.id),
|
enabled: !!(competitionId && task.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get the solution history - already sorted from oldest to newest
|
||||||
const solutionHistory = solutionsQuery.data || [];
|
const solutionHistory = solutionsQuery.data || [];
|
||||||
|
|
||||||
|
// Handle task changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (solutionHistory.length > 0 && !currentSolution) {
|
// If task changed, reset everything and load the latest solution
|
||||||
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
if (taskIdRef.current !== task.id) {
|
||||||
}
|
|
||||||
}, [solutionHistory, currentSolution]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (solutionHistory.length > 0 && currentSolution &&
|
|
||||||
solutionHistory[0].id !== currentSolution.id) {
|
|
||||||
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
|
||||||
}
|
|
||||||
}, [solutionHistory, currentSolution]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (previousTaskIdRef.current !== task.id) {
|
|
||||||
setCurrentSolution(null);
|
setCurrentSolution(null);
|
||||||
setSelectedSolutionUrl(null);
|
setSelectedSolutionUrl(null);
|
||||||
|
|
||||||
setAnswer("");
|
setAnswer("");
|
||||||
setSelectedFile(null);
|
setSelectedFile(null);
|
||||||
|
taskIdRef.current = task.id;
|
||||||
|
|
||||||
if (solutionHistory.length > 0 && !solutionsQuery.isLoading) {
|
// Wait for the query to complete
|
||||||
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
if (!solutionsQuery.isLoading && solutionHistory.length > 0) {
|
||||||
|
// Get the most recent solution (last in the array)
|
||||||
|
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
||||||
|
setCurrentSolution(latestSolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
previousTaskIdRef.current = task.id;
|
|
||||||
}
|
}
|
||||||
}, [task.id, solutionHistory, solutionsQuery.isLoading, setAnswer, setSelectedFile]);
|
}, [task.id, solutionHistory, solutionsQuery.isLoading, setAnswer, setSelectedFile]);
|
||||||
|
|
||||||
|
// Refresh current solution when the solution history changes (after a new submission)
|
||||||
|
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
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadSolutionContent = async () => {
|
const loadSolutionContent = async () => {
|
||||||
if (!currentSolution || !currentSolution.content) return;
|
if (!currentSolution || !currentSolution.content) return;
|
||||||
@@ -108,6 +113,13 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
setSelectedSolutionUrl(null);
|
setSelectedSolutionUrl(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSubmitWrapper = () => {
|
||||||
|
onSubmit();
|
||||||
|
setAnswer("");
|
||||||
|
setSelectedFile(null);
|
||||||
|
setSelectedSolutionUrl(null);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="md:w-[500px] flex flex-col gap-4">
|
<div className="md:w-[500px] flex flex-col gap-4">
|
||||||
{currentSolution ? (
|
{currentSolution ? (
|
||||||
@@ -143,7 +155,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<ActionButtons
|
<ActionButtons
|
||||||
onSubmit={onSubmit}
|
onSubmit={handleSubmitWrapper}
|
||||||
onHistoryClick={handleOpenHistory}
|
onHistoryClick={handleOpenHistory}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user