This commit is contained in:
rngsurrounded
2025-03-03 07:06:50 +09:00
parent 6c4d5e34b7
commit 5cad051e7d
@@ -42,21 +42,16 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
const solutionHistory = solutionsQuery.data || []; const solutionHistory = solutionsQuery.data || [];
const getLatestSolution = () => {
return solutionHistory.length > 0 ? solutionHistory[solutionHistory.length - 1] : null;
};
useEffect(() => { useEffect(() => {
if (solutionHistory.length > 0 && !currentSolution) { if (solutionHistory.length > 0 && !currentSolution) {
setCurrentSolution(getLatestSolution()); setCurrentSolution(solutionHistory[0]);
} }
}, [solutionHistory, currentSolution]); }, [solutionHistory, currentSolution]);
useEffect(() => { useEffect(() => {
const latestSolution = getLatestSolution(); if (solutionHistory.length > 0 && currentSolution &&
if (solutionHistory.length > 0 && currentSolution && latestSolution && solutionHistory[0].id !== currentSolution.id) {
latestSolution.id !== currentSolution.id) { setCurrentSolution(solutionHistory[0]);
setCurrentSolution(latestSolution);
} }
}, [solutionHistory, currentSolution]); }, [solutionHistory, currentSolution]);