-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fe): edit client contest list and table (#2043)
* feat(fe): redesign layout * chore(fe): hide badge if contest * feat(fe): redesign contest list * fix(fe): hide score when isJudgeResultVisible is false * fix(fe): fix type
- Loading branch information
Showing
9 changed files
with
143 additions
and
39 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
47 changes: 29 additions & 18 deletions
47
apps/frontend/app/(main)/contest/[contestId]/@tabs/problem/_components/Columns.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 |
---|---|---|
@@ -1,44 +1,55 @@ | ||
'use client' | ||
|
||
import { Badge } from '@/components/ui/badge' | ||
import { convertToLetter } from '@/lib/utils' | ||
import type { ContestProblem, Level } from '@/types/type' | ||
import { convertToLetter, dateFormatter } from '@/lib/utils' | ||
import CheckIcon from '@/public/check-green.svg' | ||
import type { ContestProblem } from '@/types/type' | ||
import type { ColumnDef } from '@tanstack/react-table' | ||
import Image from 'next/image' | ||
|
||
export const columns: ColumnDef<ContestProblem>[] = [ | ||
{ | ||
header: '#', | ||
accessorKey: 'order', | ||
cell: ({ row }) => ( | ||
<div className="h-full">{convertToLetter(row.original.order)}</div> | ||
<div className="h-full font-medium"> | ||
{convertToLetter(row.original.order)} | ||
</div> | ||
) | ||
}, | ||
{ | ||
header: 'Title', | ||
accessorKey: 'title', | ||
cell: ({ row }) => { | ||
return ( | ||
<p className="text-left text-sm md:text-base">{`${row.original.title}`}</p> | ||
<p className="text-left font-medium md:text-base">{`${row.original.title}`}</p> | ||
) | ||
} | ||
}, | ||
{ | ||
header: 'Level', | ||
accessorKey: 'difficulty', | ||
cell: ({ row }) => ( | ||
<Badge className="rounded-md" variant={row.original.difficulty as Level}> | ||
{row.original.difficulty} | ||
</Badge> | ||
) | ||
header: 'Submit', | ||
accessorKey: 'submit', | ||
cell: ({ row }) => | ||
row.original.submissionTime && ( | ||
<div className="flex items-center justify-center"> | ||
<Image src={CheckIcon} alt="check" width={24} height={24} /> | ||
</div> | ||
) | ||
}, | ||
{ | ||
header: () => 'Submission', | ||
accessorKey: 'submissionCount', | ||
cell: ({ row }) => row.original.submissionCount | ||
header: () => 'Submission Time', | ||
accessorKey: 'submissionTime', | ||
cell: ({ row }) => | ||
row.original.submissionTime && | ||
dateFormatter(row.original.submissionTime, 'YYYY-MM-DD HH:mm:ss') | ||
}, | ||
{ | ||
header: () => 'Solved', | ||
accessorKey: 'acceptedRate', | ||
cell: ({ row }) => `${row.original.acceptedRate.toFixed(2)}%` | ||
header: () => 'Score', | ||
accessorKey: 'score', | ||
cell: ({ row }) => | ||
row.original.maxScore != null ? ( | ||
`${row.original.score ?? '-'} / ${row.original.maxScore}` | ||
) : ( | ||
<></> | ||
) | ||
} | ||
] |
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
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,28 @@ | ||
import { fetcherWithAuth } from '@/lib/utils' | ||
import type { ContestProblem } from '@/types/type' | ||
|
||
interface ContestProblemsApiRes { | ||
data: ContestProblem[] | ||
} | ||
|
||
const calculateContestScore = async ({ contestId }: { contestId: string }) => { | ||
const contestProblems: ContestProblemsApiRes = await fetcherWithAuth | ||
.get(`contest/${contestId}/problem`) | ||
.json() | ||
|
||
const { totalScore, totalMaxScore } = contestProblems.data.reduce( | ||
(acc, curr) => { | ||
const score = curr.score ? parseInt(curr.score, 10) : 0 | ||
const maxScore = curr.maxScore || 0 | ||
|
||
acc.totalScore += score | ||
acc.totalMaxScore += maxScore | ||
|
||
return acc | ||
}, | ||
{ totalScore: 0, totalMaxScore: 0 } | ||
) | ||
return [totalScore, totalMaxScore] | ||
} | ||
|
||
export { calculateContestScore } |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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