From a4cae75d4450aa6407acb5dc2b9979d85d7dc2ce Mon Sep 17 00:00:00 2001 From: matushl Date: Thu, 16 Nov 2023 00:50:55 +0100 Subject: [PATCH] fix after review --- src/components/Problems/Problems.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/Problems/Problems.tsx b/src/components/Problems/Problems.tsx index 88a0d1a0..437dd129 100644 --- a/src/components/Problems/Problems.tsx +++ b/src/components/Problems/Problems.tsx @@ -2,6 +2,7 @@ import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' import axios from 'axios' import {useRouter} from 'next/router' import {FC, useState} from 'react' +import {useInterval} from 'usehooks-ts' import {Button, Link} from '@/components/Clickable/Clickable' import {SeriesWithProblems} from '@/types/api/competition' @@ -54,7 +55,16 @@ export const Problems: FC = () => { const semesterId = series?.semester ?? -1 const canSubmit = series?.can_submit ?? false const canResubmit = series?.can_resubmit ?? canSubmit - const isAfterDeadline = new Date(series?.deadline ?? '') < new Date() + const [isAfterDeadline, setIsAfterDeadline] = useState(new Date(series?.deadline ?? '') < new Date()) + + useInterval( + () => { + const isAfterDeadlineNew = new Date(series?.deadline ?? '') < new Date() + isAfterDeadlineNew && setIsAfterDeadline(isAfterDeadlineNew) + }, + // Delay to null to stop it after deadline + isAfterDeadline ? null : 1, + ) const [overrideCanRegister, setOverrideCanRegister] = useState() const [overrideIsRegistered, setOverrideIsRegistered] = useState() @@ -120,7 +130,7 @@ export const Problems: FC = () => { setDisplaySideContent={setDisplaySideContent} registered={isRegistered} canRegister={canRegister} - canSubmit={(canSubmit && !problem.submitted) || (!!problem.submitted && canResubmit)} + canSubmit={problem.submitted ? canResubmit : canSubmit} isAfterDeadline={isAfterDeadline} invalidateSeriesQuery={invalidateSeriesQuery} displayRegisterDialog={() => setDisplayRegisterDialog(true)}