diff --git a/services/frontend/src/pages/CompetitionSession/index.tsx b/services/frontend/src/pages/CompetitionSession/index.tsx index 0b4a490..c42f2be 100644 --- a/services/frontend/src/pages/CompetitionSession/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/index.tsx @@ -13,7 +13,7 @@ const CompetitionSession = () => { const { id, taskId } = useParams<{ id: string; taskId?: string }>(); const [answer, setAnswer] = useState(""); const [selectedFile, setSelectedFile] = useState(null); - const [submissionSuccess, setSubmissionSuccess] = useState(false); + const [isReloading, setIsReloading] = useState(false); const competitionId = id || ""; const queryClient = useQueryClient(); const navigate = useNavigate(); @@ -47,37 +47,20 @@ const CompetitionSession = () => { queryKey: ['solutionHistory', competitionId, taskId] }); - setSubmissionSuccess(true); // Set flag to trigger the timeout + // Start the reload countdown + setIsReloading(true); + + // Schedule the page reload + setTimeout(() => { + navigate(`/competition/${competitionId}/tasks/${taskId}`, { replace: true }); + setIsReloading(false); + }, 5000); }, onError: (error) => { console.error("Error submitting solution:", error); } }); - // Effect to handle the page reload after successful submission - useEffect(() => { - let timeoutId: number; - - if (submissionSuccess) { - timeoutId = window.setTimeout(() => { - // Reload the current page - window.location.reload(); - - // Alternative: Use React Router's navigate to refresh - // navigate(`/competition/${competitionId}/tasks/${taskId}`, { replace: true }); - - setSubmissionSuccess(false); - }, 5000); // 5 seconds timeout - } - - // Clean up timeout when component unmounts or when submissionSuccess changes - return () => { - if (timeoutId) { - window.clearTimeout(timeoutId); - } - }; - }, [submissionSuccess, competitionId, taskId, navigate]); - const competition = competitionQuery.data; const tasks = tasksQuery.data || []; const isLoading = tasksQuery.isLoading || competitionQuery.isLoading; @@ -114,6 +97,13 @@ const CompetitionSession = () => { const competitionTitle = competition?.title || "Загрузка соревнования..."; + useEffect(() => { + setAnswer(""); + setSelectedFile(null); + }, [taskId]); + + const isSubmitting = submitMutation.isPending || isReloading; + return (
{ selectedFile={selectedFile} setSelectedFile={setSelectedFile} onSubmit={handleSubmit} - isSubmitting={submitMutation.isPending} + isSubmitting={isSubmitting} /> - {submissionSuccess && ( -
-
- -

- Решение отправлено! Страница обновится через несколько секунд... -

-
-
- )}
) : (
diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx index 8113fba..049345b 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/index.tsx @@ -27,7 +27,7 @@ const TaskSolution: React.FC = ({ selectedFile, setSelectedFile, onSubmit, - isSubmitting = false + isSubmitting = false, }) => { const fileInputRef = useRef(null); const [isHistoryOpen, setIsHistoryOpen] = useState(false);