mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 23:47:10 +00:00
fix
This commit is contained in:
@@ -17,7 +17,6 @@ interface TaskSolutionProps {
|
|||||||
selectedFile: File | null;
|
selectedFile: File | null;
|
||||||
setSelectedFile: (file: File | null) => void;
|
setSelectedFile: (file: File | null) => void;
|
||||||
onSubmit: () => void;
|
onSubmit: () => void;
|
||||||
isSubmitting?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||||
@@ -33,6 +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 solutionsQuery = useQuery({
|
const solutionsQuery = useQuery({
|
||||||
queryKey: ['solutionHistory', competitionId, task.id],
|
queryKey: ['solutionHistory', competitionId, task.id],
|
||||||
@@ -44,21 +44,32 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (solutionHistory.length > 0 && !currentSolution) {
|
if (solutionHistory.length > 0 && !currentSolution) {
|
||||||
setCurrentSolution(solutionHistory[0]);
|
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
||||||
}
|
}
|
||||||
}, [solutionHistory, currentSolution]);
|
}, [solutionHistory, currentSolution]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (solutionHistory.length > 0 && currentSolution &&
|
if (solutionHistory.length > 0 && currentSolution &&
|
||||||
solutionHistory[0].id !== currentSolution.id) {
|
solutionHistory[0].id !== currentSolution.id) {
|
||||||
setCurrentSolution(solutionHistory[0]);
|
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
||||||
}
|
}
|
||||||
}, [solutionHistory, currentSolution]);
|
}, [solutionHistory, currentSolution]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (previousTaskIdRef.current !== task.id) {
|
||||||
setCurrentSolution(null);
|
setCurrentSolution(null);
|
||||||
setSelectedSolutionUrl(null);
|
setSelectedSolutionUrl(null);
|
||||||
}, [task.id]);
|
|
||||||
|
setAnswer("");
|
||||||
|
setSelectedFile(null);
|
||||||
|
|
||||||
|
if (solutionHistory.length > 0 && !solutionsQuery.isLoading) {
|
||||||
|
setCurrentSolution(solutionHistory[solutionHistory.length - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
previousTaskIdRef.current = task.id;
|
||||||
|
}
|
||||||
|
}, [task.id, solutionHistory, solutionsQuery.isLoading, setAnswer, setSelectedFile]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadSolutionContent = async () => {
|
const loadSolutionContent = async () => {
|
||||||
@@ -121,6 +132,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
fileInputRef={fileInputRef}
|
fileInputRef={fileInputRef}
|
||||||
existingFileUrl={selectedSolutionUrl}
|
existingFileUrl={selectedSolutionUrl}
|
||||||
onClearExistingFile={handleClearExistingFile}
|
onClearExistingFile={handleClearExistingFile}
|
||||||
|
isLoading={isSubmitting}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user