-
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.
fix(fe): fix
GotoFirstProblemButton
error (#2327)
fix(fe): fix GotoFirstProblemButton error
- Loading branch information
Showing
2 changed files
with
14 additions
and
33 deletions.
There are no files selected for viewing
37 changes: 12 additions & 25 deletions
37
...tend/app/(client)/(main)/contest/[contestId]/@tabs/_components/GoToFirstProblemButton.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,36 +1,23 @@ | ||
'use client' | ||
|
||
import { contestProblemQueries } from '@/app/(client)/_libs/queries/contestProblem' | ||
import { getContestProblemList } from '@/app/(client)/_libs/apis/contestProblem' | ||
import { Button } from '@/components/shadcn/button' | ||
import { Skeleton } from '@/components/shadcn/skeleton' | ||
import { useSuspenseQuery } from '@tanstack/react-query' | ||
import { useRouter } from 'next/navigation' | ||
import Link from 'next/link' | ||
|
||
interface GoToFirstProblemButtonProps { | ||
contestId: number | ||
} | ||
|
||
export function GoToFirstProblemButton({ | ||
export async function GoToFirstProblemButton({ | ||
contestId | ||
}: GoToFirstProblemButtonProps) { | ||
const router = useRouter() | ||
const { data: firstProblemId } = useSuspenseQuery({ | ||
...contestProblemQueries.list({ contestId, take: 1 }), | ||
select: (data) => data.data.at(0)?.id | ||
}) | ||
const { data } = await getContestProblemList({ contestId, take: 1 }) | ||
|
||
return ( | ||
<Button | ||
className="px-12 py-6 text-lg font-light" | ||
onClick={() => | ||
router.push(`/contest/${contestId}/problem/${firstProblemId}`) | ||
} | ||
> | ||
Go To First Problem! | ||
</Button> | ||
) | ||
} | ||
const firstProblemId = data.at(0)?.id | ||
|
||
export function GoToFirstProblemButtonFallback() { | ||
return <Skeleton className="h-12 w-60" /> | ||
return firstProblemId ? ( | ||
<Button className="px-12 py-6 text-lg font-light"> | ||
<Link href={`/contest/${contestId}/problem/${firstProblemId}`}> | ||
Go To First Problem! | ||
</Link> | ||
</Button> | ||
) : null | ||
} |
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