Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Matushl committed Nov 15, 2023
1 parent c837327 commit a4cae75
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/Problems/Problems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<boolean>(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<boolean>()
const [overrideIsRegistered, setOverrideIsRegistered] = useState<boolean>()
Expand Down Expand Up @@ -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)}
Expand Down

0 comments on commit a4cae75

Please sign in to comment.