-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix contest submissions table
- Loading branch information
Showing
18 changed files
with
501 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,5 @@ Thumbs.db | |
|
||
.nx/cache | ||
.nx/workspace-data | ||
|
||
**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FC } from 'react'; | ||
import { cn } from 'tw-react-components'; | ||
|
||
import { Judging, Prisma } from '@prisma/client'; | ||
|
||
import { dateComparator } from '@core/utils'; | ||
|
||
import { JUDGING_RESULT_LABELS } from '../constants'; | ||
|
||
type Props = { | ||
submission: Prisma.SubmissionGetPayload<{ include: { judgings: true } }>; | ||
}; | ||
|
||
export const SubmissionResult: FC<Props> = ({ submission }) => { | ||
const judging = submission.judgings | ||
.slice() | ||
.sort(dateComparator<Judging>('startTime', true)) | ||
.shift(); | ||
return ( | ||
<b | ||
className={cn({ | ||
'text-green-700 dark:text-green-400': judging?.result === 'ACCEPTED', | ||
'text-red-700 dark:text-red-400': judging?.result && judging.result !== 'ACCEPTED', | ||
'text-gray-500 dark:text-gray-400': !judging?.result, | ||
})} | ||
> | ||
{JUDGING_RESULT_LABELS[judging?.result ?? 'PENDING']} | ||
</b> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { JudgingResult } from '@prisma/client'; | ||
|
||
export const JUDGING_RESULT_LABELS: Record<JudgingResult | 'PENDING', string> = { | ||
ACCEPTED: 'Accepted', | ||
WRONG_ANSWER: 'Wrong Answer', | ||
TIME_LIMIT_EXCEEDED: 'Time Limit Exceeded', | ||
MEMORY_LIMIT_EXCEEDED: 'Memory Limit Exceeded', | ||
RUNTIME_ERROR: 'Runtime Error', | ||
COMPILATION_ERROR: 'Compile Error', | ||
SYSTEM_ERROR: 'System Error', | ||
PENDING: 'Pending', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function dateComparator<T>(field: keyof T, inv = false): (a: T, b: T) => number { | ||
return (a, b) => | ||
new Date((inv ? b : a)[field] as Date).getTime() - | ||
new Date((inv ? a : b)[field] as Date).getTime(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function formatRestTime(time: number, withSeconds = true): string { | ||
if (time <= 0) return 'contest over'; | ||
const days = Math.floor(time / 86400); | ||
const hours = Math.floor((time % 86400) / 3600); | ||
const minutes = Math.floor((time % 3600) / 60); | ||
const seconds = Math.floor(time % 60); | ||
|
||
let result = ''; | ||
days && (result += `${days}d `); | ||
(days || hours) && (result += `${hours.toString().padStart(2, '0')}:`); | ||
result += minutes.toString().padStart(2, '0'); | ||
withSeconds && (result += `:${seconds.toString().padStart(2, '0')}`); | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
export * from './files'; | ||
|
||
export * from './dateComparator'; | ||
export * from './formatBytes'; | ||
export * from './formatRestTime'; | ||
export * from './getDisplayDate'; | ||
export * from './getRandomHexColor'; | ||
export * from './getRGBColorContrast'; | ||
export * from './isContestRunning'; | ||
export * from './queryParser'; | ||
export * from './request'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Contest } from '@prisma/client'; | ||
|
||
export function isContestRunning(contest?: Contest): boolean { | ||
const now = Date.now(); | ||
return ( | ||
!!contest && | ||
!!contest.endTime && | ||
new Date(contest.startTime).getTime() < now && | ||
now < new Date(contest.endTime).getTime() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { MessagesSquareIcon, PresentationIcon, SendIcon, StarsIcon } from 'lucide-react'; | ||
import { FC, useEffect, useState } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { DropdownMenu, Flex, Sidebar, useSidebar } from 'tw-react-components'; | ||
|
||
import { useFindManyContest } from '@models'; | ||
|
||
export const ContestsSection: FC = () => { | ||
const { isMobile } = useSidebar(); | ||
const [now, setNow] = useState(new Date()); | ||
|
||
const { data: contests } = useFindManyContest({ | ||
where: { | ||
enabled: true, | ||
activateTime: { lte: now }, | ||
}, | ||
select: { id: true, name: true, scoreCaches: { select: { restrictedPending: true } } }, | ||
orderBy: { activateTime: 'asc' }, | ||
}); | ||
|
||
useEffect(() => { | ||
if (import.meta.env.MODE === 'development') return; | ||
|
||
const interval = setInterval(() => { | ||
setNow(new Date()); | ||
}, 5000); | ||
|
||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
return ( | ||
<Sidebar.Group> | ||
<Sidebar.GroupLabel>Active Contests</Sidebar.GroupLabel> | ||
<Sidebar.GroupContent> | ||
<Sidebar.Menu> | ||
{contests?.map((contest) => { | ||
const totalPendingSubmissions = contest.scoreCaches.reduce( | ||
(acc, { restrictedPending }) => acc + restrictedPending, | ||
0, | ||
); | ||
|
||
return ( | ||
<DropdownMenu key={contest.id}> | ||
<Sidebar.MenuItem> | ||
<DropdownMenu.Trigger asChild> | ||
<Sidebar.MenuButton> | ||
<StarsIcon /> | ||
{contest.name} | ||
{totalPendingSubmissions > 0 && ( | ||
<Flex | ||
className="ml-auto h-5 w-5 rounded bg-orange-500" | ||
align="center" | ||
justify="center" | ||
> | ||
{totalPendingSubmissions} | ||
</Flex> | ||
)} | ||
</Sidebar.MenuButton> | ||
</DropdownMenu.Trigger> | ||
<DropdownMenu.Content | ||
className="min-w-56 rounded-lg text-sm" | ||
side={isMobile ? 'bottom' : 'right'} | ||
align={isMobile ? 'end' : 'start'} | ||
> | ||
<Link to={`/contests/${contest.id}/submissions`}> | ||
<DropdownMenu.Item className="cursor-pointer"> | ||
<DropdownMenu.Icon icon={SendIcon} /> | ||
Submissions | ||
</DropdownMenu.Item> | ||
</Link> | ||
<Link to={`/contests/${contest.id}/clarifications`}> | ||
<DropdownMenu.Item className="cursor-pointer"> | ||
<DropdownMenu.Icon icon={MessagesSquareIcon} /> | ||
Clarifications | ||
</DropdownMenu.Item> | ||
</Link> | ||
<Link to={`/contests/${contest.id}/scoreboard`}> | ||
<DropdownMenu.Item className="cursor-pointer"> | ||
<DropdownMenu.Icon icon={PresentationIcon} /> | ||
Scoreboard | ||
</DropdownMenu.Item> | ||
</Link> | ||
</DropdownMenu.Content> | ||
</Sidebar.MenuItem> | ||
</DropdownMenu> | ||
); | ||
})} | ||
</Sidebar.Menu> | ||
</Sidebar.GroupContent> | ||
</Sidebar.Group> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
apps/client/src/pages/admin/views/contests/ContestView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { GraduationCapIcon } from 'lucide-react'; | ||
import { FC } from 'react'; | ||
import { Outlet, useLocation, useNavigate, useParams } from 'react-router-dom'; | ||
import { Flex, Tabs } from 'tw-react-components'; | ||
|
||
import { PageTemplate } from '@core/components'; | ||
import { useFindFirstContest } from '@models'; | ||
|
||
export const ContestView: FC = () => { | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const { id: contestId } = useParams(); | ||
const currentTab = location.pathname.split('/').pop(); | ||
|
||
const { data: contest } = useFindFirstContest({ where: { id: parseInt(contestId ?? '-1') } }); | ||
|
||
return ( | ||
<Tabs className="w-full" value={currentTab} onValueChange={(tab) => navigate(tab)}> | ||
<PageTemplate | ||
icon={GraduationCapIcon} | ||
title={ | ||
<Flex align="center" justify="between" fullWidth> | ||
{contest?.name} | ||
<Tabs.List className="ml-2 w-fit text-sm [&>button]:h-6"> | ||
<Tabs.Trigger value="submissions">Submissions</Tabs.Trigger> | ||
<Tabs.Trigger value="clarifications">Clarifications</Tabs.Trigger> | ||
<Tabs.Trigger value="scoreboard">Scoreboard</Tabs.Trigger> | ||
</Tabs.List> | ||
</Flex> | ||
} | ||
> | ||
<Outlet /> | ||
</PageTemplate> | ||
</Tabs> | ||
); | ||
}; |
Oops, something went wrong.