-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 질문 탭에 준비중인 기능이라는 텍스트 표시 * refactor: Quiz Submission 테이블 관련 API 분리 * feat: 특정 유저의 특정 퀴즈에 대한 제출 정보 가져오는 로직 작성 * feat: 솔루션 페이지 컨텐츠 접근 제한 로직 작성 * fix: 퀴즈 제출 내용 변경시 아직 화면에 반영되지 않는 오류 * refactor: getSubmittedQuiz 재 추가 * style: detailOfQuiz 로 이름 변경
- Loading branch information
1 parent
44f5c70
commit 4be0479
Showing
14 changed files
with
153 additions
and
58 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import LoadingSpinner from '@/components/common/loading-spinner/loading-spinner'; | ||
|
||
export default function Loading() { | ||
return ( | ||
<section className="flex min-h-[90vh] items-center justify-center overflow-hidden"> | ||
<LoadingSpinner size="3xl" className="text-blue-primary" /> | ||
</section> | ||
); | ||
} |
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,15 @@ | ||
export default async function Page({ params }: { params: { id: string } }) { | ||
import Link from 'next/link'; | ||
import Button from '@/components/common/buttons/button'; | ||
|
||
export default function Page({ params }: { params: { id: string } }) { | ||
const quizId = Number(params.id) ?? 0; | ||
|
||
return <section>{quizId}번 퀴즈에 대한 질문 페이지</section>; | ||
return ( | ||
<div className="flex flex-col items-center gap-6"> | ||
<h2 className="text-xl font-semibold">준비중인 기능이에요!</h2> | ||
<Link replace href={`/quizzes/${quizId}`}> | ||
<Button>퀴즈로 이동하기</Button> | ||
</Link> | ||
</div> | ||
); | ||
} |
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 { createClient } from '@/utils/supabase/client'; | ||
import { SupabaseClient } from '@supabase/supabase-js'; | ||
|
||
const quizSubmissionAPI = { | ||
getSubmissionsOfUser: async (userId: string) => { | ||
const supabase: SupabaseClient<Database> = createClient(); | ||
|
||
const { data } = await supabase | ||
.from('quizsubmissions') | ||
.select(`*, quizzes (id, *)`) | ||
.eq('user_id', userId); | ||
|
||
return data; | ||
}, | ||
|
||
getSubmissionOfUser: async (userId: string, quizId: number) => { | ||
const supabase: SupabaseClient<Database> = createClient(); | ||
|
||
const { data } = await supabase | ||
.from('quizsubmissions') | ||
.select(`*, quizzes (id, *)`) | ||
.match({ user_id: userId, quiz_id: quizId }) | ||
.limit(1) | ||
.single(); | ||
|
||
return data; | ||
}, | ||
|
||
postSubmission: async (params: { quizId: number; choiceId: number }) => { | ||
const { quizId, choiceId } = params; | ||
|
||
const res = await fetch('/api/quiz-submission', { | ||
method: 'POST', | ||
body: JSON.stringify({ quizId, choiceId }), | ||
}); | ||
|
||
const json = await res.json(); | ||
|
||
if (!res.ok) { | ||
throw new Error(json.error); | ||
} | ||
|
||
return json; | ||
}, | ||
}; | ||
|
||
export default quizSubmissionAPI; |
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,17 @@ | ||
import { useSuspenseQuery, useMutation } from '@tanstack/react-query'; | ||
import quizOptions from './options'; | ||
import quizSubmissionAPI from './api'; | ||
|
||
export function useGetQuizSubmissions(userId: string) { | ||
return useSuspenseQuery(quizOptions.all(userId)); | ||
} | ||
|
||
export function useGetQuizSubmission(userId: string, quizId: number) { | ||
return useSuspenseQuery(quizOptions.detailOfQuiz(userId, quizId)); | ||
} | ||
|
||
export function useSubmitQuizSubmission() { | ||
return useMutation({ | ||
mutationFn: quizSubmissionAPI.postSubmission, | ||
}); | ||
} |
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,19 @@ | ||
import { queryOptions } from '@tanstack/react-query'; | ||
import quizSubmissionAPI from './api'; | ||
|
||
const quizSubmissionOptions = { | ||
default: ['quizsubmissions'] as const, | ||
|
||
all: (userId: string) => | ||
queryOptions({ | ||
queryKey: [...quizSubmissionOptions.default, userId], | ||
queryFn: () => quizSubmissionAPI.getSubmissionsOfUser(userId), | ||
}), | ||
|
||
detailOfQuiz: (userId: string, quizId: number) => ({ | ||
queryKey: [...quizSubmissionOptions.default, userId, quizId], | ||
queryFn: () => quizSubmissionAPI.getSubmissionOfUser(userId, quizId), | ||
}), | ||
}; | ||
|
||
export default quizSubmissionOptions; |
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