-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(fe): use tanstack query for MySubmission #2250
Open
Kimhyojung0810
wants to merge
11
commits into
main
Choose a base branch
from
t1090-refactor-MySubmission
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ead514f
feat(fe): add submission api call functions and queries
Kimhyojung0810 bf5a48c
refactor(fe): refactor MySubmission component
Kimhyojung0810 6a2c911
fix(fe): delete comment
Kimhyojung0810 96ba378
refactor(fe): add error boundary
Kimhyojung0810 c004358
Merge branch 'main' into t1090-refactor-MySubmission
Kimhyojung0810 7f7b0e9
fix(fe): change interface name
Kimhyojung0810 5ce8b05
Merge branch 't1090-refactor-MySubmission' of https://github.com/skku…
Kimhyojung0810 0953011
fix(fe): fix ErrorBoundary and Suspense
Kimhyojung0810 26e8f34
fix(fe): use submission datail query in SubmissionDetailContent
Kimhyojung0810 8e610f9
fix(fe): not using submission detail query in MySubmission
Kimhyojung0810 1a708bf
fix(fe): fix submission query
Kimhyojung0810 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use client' | ||
|
||
import { submissionQueries } from '@/app/(client)/_libs/queries/submission' | ||
import CodeEditor from '@/components/CodeEditor' | ||
import { ScrollArea, ScrollBar } from '@/components/shadcn/scroll-area' | ||
import { | ||
|
@@ -11,17 +12,30 @@ import { | |
TableRow | ||
} from '@/components/shadcn/table' | ||
import { dateFormatter, getResultColor } from '@/libs/utils' | ||
import type { ContestProblem, Language, SubmissionDetail } from '@/types/type' | ||
import type { ContestProblem, Language } from '@/types/type' | ||
import { ErrorBoundary } from '@suspensive/react' | ||
import { useSuspenseQuery } from '@tanstack/react-query' | ||
import { Suspense } from 'react' | ||
|
||
export default function SubmissionDetailContent({ | ||
submissionId, | ||
submission, | ||
problem | ||
}: { | ||
interface SubmissionDetailProps { | ||
contestId: number | ||
submissionId: number | ||
submission: SubmissionDetail | ||
problem: ContestProblem | ||
}) { | ||
} | ||
|
||
function SubmissionDetail({ | ||
contestId, | ||
submissionId, | ||
problem | ||
}: SubmissionDetailProps) { | ||
const { data: submission } = useSuspenseQuery( | ||
submissionQueries.detail({ | ||
contestId, | ||
submissionId, | ||
problemId: problem.id | ||
}) | ||
) | ||
|
||
return ( | ||
<ScrollArea className="mt-5 max-h-[540px] w-[760px]"> | ||
<div className="ml-20 flex w-[612px] flex-col gap-4"> | ||
|
@@ -121,3 +135,21 @@ export default function SubmissionDetailContent({ | |
</ScrollArea> | ||
) | ||
} | ||
|
||
export default function SubmissionDetailContetnt({ | ||
contestId, | ||
submissionId, | ||
problem | ||
}: SubmissionDetailProps) { | ||
return ( | ||
<ErrorBoundary fallback={null}> | ||
<Suspense fallback={null}> | ||
Comment on lines
+145
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error boundary를 fallback으로 |
||
<SubmissionDetail | ||
contestId={contestId} | ||
submissionId={submissionId} | ||
problem={problem} | ||
/> | ||
</Suspense> | ||
</ErrorBoundary> | ||
) | ||
} |
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,47 @@ | ||
import { safeFetcherWithAuth } from '@/libs/utils' | ||
import type { Submission, SubmissionDetail } from '@/types/type' | ||
import type { PaginationQueryParams } from './types' | ||
|
||
export interface GetSubmissionListRequest extends PaginationQueryParams { | ||
contestId: number | ||
problemId: number | ||
} | ||
|
||
export interface GetSubmissionListResponse { | ||
data: Submission[] | ||
total: number | ||
} | ||
|
||
export const getSubmissionList = async ({ | ||
contestId, | ||
problemId, | ||
...searchParams | ||
}: GetSubmissionListRequest): Promise<GetSubmissionListResponse> => { | ||
const response = await safeFetcherWithAuth.get( | ||
`contest/${contestId}/submission`, | ||
{ | ||
searchParams: { ...searchParams, problemId } | ||
} | ||
) | ||
const data = await response.json<GetSubmissionListResponse>() | ||
return data | ||
} | ||
|
||
export interface GetSubmissionDetailRequest { | ||
contestId: number | ||
problemId: number | ||
submissionId: number | ||
} | ||
|
||
export const getSubmissionDetail = async ({ | ||
contestId, | ||
problemId, | ||
submissionId | ||
}: GetSubmissionDetailRequest): Promise<SubmissionDetail> => { | ||
const response = await safeFetcherWithAuth.get(`submission/${submissionId}`, { | ||
searchParams: { problemId, contestId } | ||
}) | ||
|
||
const data = await response.json<SubmissionDetail>() | ||
return data | ||
} |
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,39 @@ | ||
import { queryOptions } from '@tanstack/react-query' | ||
import { | ||
getSubmissionList, | ||
getSubmissionDetail, | ||
type GetSubmissionListRequest, | ||
type GetSubmissionDetailRequest | ||
} from '../apis/submission' | ||
|
||
export const submissionQueries = { | ||
all: ({ contestId, problemId }: { contestId: number; problemId: number }) => | ||
['submission', 'contest', contestId, { problemId }] as const, | ||
|
||
lists: ({ contestId, problemId }: { contestId: number; problemId: number }) => | ||
[...submissionQueries.all({ contestId, problemId }), 'list'] as const, | ||
|
||
list: ({ contestId, problemId, ...searchParams }: GetSubmissionListRequest) => | ||
queryOptions({ | ||
queryKey: [ | ||
...submissionQueries.lists({ contestId, problemId }), | ||
{ ...searchParams } | ||
] as const, | ||
queryFn: () => | ||
getSubmissionList({ contestId, problemId, ...searchParams }) | ||
}), | ||
|
||
detail: ({ | ||
contestId, | ||
submissionId, | ||
problemId | ||
}: GetSubmissionDetailRequest) => | ||
queryOptions({ | ||
queryKey: [ | ||
...submissionQueries.all({ contestId, problemId }), | ||
'detail', | ||
submissionId | ||
] as const, | ||
queryFn: () => getSubmissionDetail({ contestId, submissionId, problemId }) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useSuspenseQuery
를 사용하면isLoading
을 사용하지 않아도 돼요!