-
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.
refactor(fe): use tanstack query for client-side data fetching (#2232)
* chore(fe): add react query dev tool * chore(fe): update contest problem and problem detail type * fix(fe): fix params type * chore(fe): add todo comment * feat(fe): add contest problem api call functions and queries * refactor(fe): use api call function * refactor(fe): refactor contest problem dropdown component * refactor(fe): refactor register button component * refactor(fe): not use suspense query for contest problem dropdown
- Loading branch information
Showing
19 changed files
with
319 additions
and
293 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
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
20 changes: 6 additions & 14 deletions
20
apps/frontend/app/(client)/(code-editor)/contest/[contestId]/problem/[problemId]/page.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,30 +1,22 @@ | ||
import { EditorDescription } from '@/app/(client)/(code-editor)/_components/EditorDescription' | ||
import type { GetContestProblemDetailResponse } from '@/app/(client)/_libs/apis/contestProblem' | ||
import { fetcherWithAuth } from '@/libs/utils' | ||
import type { ContestProblem, ProblemDetail } from '@/types/type' | ||
import { redirect } from 'next/navigation' | ||
|
||
export default async function DescriptionPage({ | ||
params | ||
}: { | ||
params: { problemId: number; contestId: number } | ||
params: { problemId: string; contestId: string } | ||
}) { | ||
const { problemId, contestId } = params | ||
const res = await fetcherWithAuth(`contest/${contestId}/problem/${problemId}`) | ||
|
||
// TODO: use `getContestProblemDetail` from _libs/apis folder & use error boundary | ||
const res = await fetcherWithAuth(`contest/${contestId}/problem/${problemId}`) | ||
if (!res.ok && res.status === 403) { | ||
redirect(`/contest/${contestId}/finished/problem/${problemId}`) | ||
} | ||
|
||
const contestProblem: { problem: ProblemDetail } = await res.json() | ||
const { problem, order } = await res.json<GetContestProblemDetailResponse>() | ||
|
||
const contestProblems: { problems: ContestProblem[] } = await fetcherWithAuth( | ||
`contest/${params.contestId}/problem` | ||
).json() | ||
return ( | ||
<EditorDescription | ||
problem={contestProblem.problem} | ||
contestProblems={contestProblems.problems} | ||
isContest={true} | ||
/> | ||
) | ||
return <EditorDescription problem={{ ...problem, order }} isContest={true} /> | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use client' | ||
|
||
import { contestProblemQueries } from '@/app/(client)/_libs/queries/contestProblem' | ||
import { Button } from '@/components/shadcn/button' | ||
import { Skeleton } from '@/components/shadcn/skeleton' | ||
import { useSuspenseQuery } from '@tanstack/react-query' | ||
import { useRouter } from 'next/navigation' | ||
|
||
interface GoToFirstProblemButtonProps { | ||
contestId: number | ||
} | ||
|
||
export function GoToFirstProblemButton({ | ||
contestId | ||
}: GoToFirstProblemButtonProps) { | ||
const router = useRouter() | ||
const { data: firstProblemId } = useSuspenseQuery({ | ||
...contestProblemQueries.list({ contestId, take: 1 }), | ||
select: (data) => data.data.at(0)?.id | ||
}) | ||
|
||
return ( | ||
<Button | ||
className="px-12 py-6 text-lg font-light" | ||
onClick={() => | ||
router.push(`/contest/${contestId}/problem/${firstProblemId}`) | ||
} | ||
> | ||
Go To First Problem! | ||
</Button> | ||
) | ||
} | ||
|
||
export function GoToFirstProblemButtonFallback() { | ||
return <Skeleton className="h-12 w-60" /> | ||
} |
Oops, something went wrong.