-
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.
Merge branch 'main' into t1080-apply-class-validator-on-user-tc
- Loading branch information
Showing
18 changed files
with
259 additions
and
120 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
apps/frontend/app/(client)/(code-editor)/_components/ContestProblemDropdown.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,69 @@ | ||
'use client' | ||
|
||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger | ||
} from '@/components/shadcn/dropdown-menu' | ||
import { cn, convertToLetter, fetcherWithAuth } from '@/libs/utils' | ||
import checkIcon from '@/public/icons/check-green.svg' | ||
import type { ContestProblem, ProblemDetail } from '@/types/type' | ||
import { useQuery } from '@tanstack/react-query' | ||
import Image from 'next/image' | ||
import Link from 'next/link' | ||
import { FaSortDown } from 'react-icons/fa' | ||
|
||
interface ContestProblemsResponse { | ||
data: ContestProblem[] | ||
total: number | ||
} | ||
|
||
interface ContestProblemDropdownProps { | ||
problem: ProblemDetail | ||
problemId: number | ||
contestId: number | ||
} | ||
|
||
export default function ContestProblemDropdown({ | ||
problem, | ||
problemId, | ||
contestId | ||
}: ContestProblemDropdownProps) { | ||
const { data: contestProblems } = useQuery< | ||
ContestProblemsResponse | undefined | ||
>({ | ||
queryKey: ['contest', contestId, 'problems'], | ||
queryFn: () => | ||
fetcherWithAuth.get(`contest/${contestId}/problem?take=20`).json() | ||
}) | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="flex gap-1 text-lg text-white outline-none"> | ||
<h1>{`${convertToLetter(contestProblems?.data.find((item) => item.id === Number(problemId))?.order as number)}. ${problem.title}`}</h1> | ||
<FaSortDown /> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="border-slate-700 bg-slate-900"> | ||
{contestProblems?.data.map((p) => ( | ||
<Link key={p.id} href={`/contest/${contestId}/problem/${p.id}`}> | ||
<DropdownMenuItem | ||
className={cn( | ||
'flex justify-between text-white hover:cursor-pointer focus:bg-slate-800 focus:text-white', | ||
problem.id === p.id && | ||
'text-primary-light focus:text-primary-light' | ||
)} | ||
> | ||
{`${convertToLetter(p.order)}. ${p.title}`} | ||
{p.submissionTime && ( | ||
<div className="flex items-center justify-center pl-2"> | ||
<Image src={checkIcon} alt="check" width={16} height={16} /> | ||
</div> | ||
)} | ||
</DropdownMenuItem> | ||
</Link> | ||
))} | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
) | ||
} |
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
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
Oops, something went wrong.