diff --git a/src/app/(routes)/document/[id]/(main)/page.tsx b/src/app/(routes)/document/[id]/(main)/page.tsx index 934e8b15..c77978cb 100644 --- a/src/app/(routes)/document/[id]/(main)/page.tsx +++ b/src/app/(routes)/document/[id]/(main)/page.tsx @@ -3,7 +3,7 @@ import DocumentFloatingButton from '@/features/document/components/document-floa import { QuizListProvider } from '@/features/document/contexts/quiz-list-context' import DocumentContent from '@/features/document/screens/document-content' import Quiz from '@/features/document/screens/quiz' -import { fetchDocumentDetail } from '@/requests/document/server' +import { getDocumentDetail } from '@/requests/document/server' interface Props { params: { @@ -19,7 +19,7 @@ const DocumentDetailPage = async ({ params, searchParams }: Props) => { const tab = searchParams.tab ?? 'document-content' const activeTab = ['document-content', 'quiz'].includes(tab) ? tab : 'document-content' - const data = await fetchDocumentDetail(Number(id)) + const data = await getDocumentDetail(Number(id)) return (
diff --git a/src/app/(routes)/main/page.tsx b/src/app/(routes)/main/page.tsx index a1538b09..900c4144 100644 --- a/src/app/(routes)/main/page.tsx +++ b/src/app/(routes)/main/page.tsx @@ -9,12 +9,12 @@ import ReviewTop5Container from '@/features/document/components/review-top5-cont import InterestedCategoryCollections from '@/features/collection/components/interested-category-collections' import RandomQuizLottie from '@/features/quiz/components/random-quiz-lottie' import BombQuizLottie from '@/features/quiz/components/bomb-quiz-lottie' -import { fetchTodayQuizSetId } from '@/requests/quiz/server' -import { fetchDocuments } from '@/requests/document/server' +import { getTodayQuizSetId } from '@/requests/quiz/server' +import { getDocuments } from '@/requests/document/server' const Home = async () => { - const { quizSetId, createdAt, type } = await fetchTodayQuizSetId() - const { documents } = await fetchDocuments() + const { quizSetId, createdAt, type } = await getTodayQuizSetId() + const { documents } = await getDocuments() const isEmpty = !documents || documents.length === 0 const todayQuizState = isEmpty ? 'EMPTY' : type === 'READY' ? 'ARRIVED' : 'NOT_ARRIVED' diff --git a/src/app/(routes)/quiz/[id]/page.tsx b/src/app/(routes)/quiz/[id]/page.tsx index ecf4d19b..d0d84e6c 100644 --- a/src/app/(routes)/quiz/[id]/page.tsx +++ b/src/app/(routes)/quiz/[id]/page.tsx @@ -1,6 +1,7 @@ import IntroAndQuizView from '@/features/quiz/screen/intro-and-quiz-view' import { getQuizSetTypeEnum } from '@/features/quiz/utils' -import { fetchQuizSetById } from '@/requests/quiz/client' +import { getCollectionInfo } from '@/requests/collection/server' +import { getQuizSetById } from '@/requests/quiz/server' import { notFound } from 'next/navigation' interface Props { @@ -13,8 +14,7 @@ interface Props { // 문서 퀴즈일 경우 documentName?: string directoryEmoji?: string - // 콜렉션 퀴즈일 경우 - collectionId?: string + // 콜렉션 퀴즈일 경우 (id는 params로 받음) collectionName?: string collectionEmoji?: string } @@ -22,16 +22,22 @@ interface Props { const QuizDetailPage = async ({ params, searchParams }: Props) => { const { - quizType, + quizType = 'today', createdAt, documentName, directoryEmoji, - collectionId, collectionName, collectionEmoji, } = searchParams - const quizSet = await fetchQuizSetById({ + // const isTodayQuiz = quizType === 'today' + // const isDocumentQuiz = quizType === 'document' + // const isCollectionQuiz = quizType === 'collection' + const collectionId = Number(params.id) + // const collection = isCollectionQuiz ? await getCollectionInfo(collectionId) : null + // const isCreateQuiz = quizType === 'create' + + const quizSet = await getQuizSetById({ quizSetId: params.id, collectionId: quizType === 'collection' ? Number(collectionId) : undefined, quizSetType: getQuizSetTypeEnum(quizType), diff --git a/src/features/collection/components/detail-info/index.tsx b/src/features/collection/components/detail-info/index.tsx index be5492f1..789a4eee 100644 --- a/src/features/collection/components/detail-info/index.tsx +++ b/src/features/collection/components/detail-info/index.tsx @@ -98,7 +98,9 @@ const DetailInfo = ({ id }: Props) => { )} - + {/* 이동 /quiz/[id] - searchParams로 collectionId, createdAt, collectionName, collectionEmoji 넣어서 */} diff --git a/src/features/quiz/components/replay-quiz-drawer.tsx b/src/features/quiz/components/replay-quiz-drawer.tsx index f391eaa2..aa076637 100644 --- a/src/features/quiz/components/replay-quiz-drawer.tsx +++ b/src/features/quiz/components/replay-quiz-drawer.tsx @@ -30,7 +30,7 @@ const ReplayQuizDrawer = ({ const { mutate: replayDocumentQuizMutate } = useReplayDocumentQuiz() - const [quizType, setQuizType] = useState('RANDOM') + const [quizType, setQuizType] = useState('RANDOM') const [quizCount, setQuizCount] = useState(savedQuizCount) const minQuizCount = savedQuizCount > 5 ? 5 : 1 diff --git a/src/requests/collection/server.ts b/src/requests/collection/server.ts index 2ededa8f..951a8c2c 100644 --- a/src/requests/collection/server.ts +++ b/src/requests/collection/server.ts @@ -3,6 +3,17 @@ import { API_ENDPOINTS } from '@/shared/configs/endpoint' import { httpServer } from '@/shared/lib/axios/http-server' +export const getCollectionInfo = async (id: number) => { + try { + const { data } = await httpServer.get( + API_ENDPOINTS.COLLECTION.GET.INFO(id) + ) + return data + } catch (error) { + throw error + } +} + /** server에서만 사용 */ export const getBookmarkedCollections = async () => { try { diff --git a/src/requests/document/client.tsx b/src/requests/document/client.tsx index 8f3c3eec..bc0d8ddd 100644 --- a/src/requests/document/client.tsx +++ b/src/requests/document/client.tsx @@ -8,8 +8,7 @@ type GetDocumentsParams = { sortOption?: Document.Sort } -/** client에서만 사용 */ -export const fetchDocuments = async (params?: GetDocumentsParams) => { +export const getDocuments = async (params?: GetDocumentsParams) => { const defaultSortOption = 'CREATED_AT' const DocsParams = @@ -31,8 +30,8 @@ export const fetchDocuments = async (params?: GetDocumentsParams) => { } } -/** client에서만 사용 */ -export const fetchDocumentDetail = async (documentId?: number) => { +// document id page 컴포넌트에서도 사용됨 수정 필요 +export const getDocumentDetail = async (documentId?: number) => { if (documentId === null || documentId === undefined) return try { diff --git a/src/requests/document/hooks.ts b/src/requests/document/hooks.ts index f5623b14..e267a12b 100644 --- a/src/requests/document/hooks.ts +++ b/src/requests/document/hooks.ts @@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query' import { useSession } from 'next-auth/react' import { createDocument } from './create-document' -import { deleteDocument, fetchDocumentDetail, moveDocument, searchDocument } from './client' +import { deleteDocument, getDocumentDetail, moveDocument, searchDocument } from './client' import { queries } from '@/shared/lib/tanstack-query/query-keys' import { getQueryClient } from '@/shared/lib/tanstack-query/client' import { updateDocument } from './update-document' @@ -13,7 +13,7 @@ import { updateDocument } from './update-document' */ export const useGetDocumentDetail = () => { return useMutation({ - mutationFn: async (documentId: number) => fetchDocumentDetail(documentId), + mutationFn: async (documentId: number) => getDocumentDetail(documentId), }) } diff --git a/src/requests/document/server.ts b/src/requests/document/server.ts index b0707380..9e535428 100644 --- a/src/requests/document/server.ts +++ b/src/requests/document/server.ts @@ -8,8 +8,7 @@ type GetDocumentsParams = { sortOption?: Document.Sort } -/** server에서만 사용 */ -export const fetchDocuments = async (params?: GetDocumentsParams) => { +export const getDocuments = async (params?: GetDocumentsParams) => { const defaultSortOption = 'CREATED_AT' const DocsParams = @@ -34,9 +33,8 @@ export const fetchDocuments = async (params?: GetDocumentsParams) => { } } -/** server에서만 사용 */ -export const fetchDocumentDetail = async (documentId?: number) => { - if (documentId === null || documentId === undefined) return +export const getDocumentDetail = async (documentId?: number) => { + if (documentId == null) return try { const { data } = await httpServer.get( diff --git a/src/requests/quiz/server.tsx b/src/requests/quiz/server.tsx index e373d847..9a6c0ed6 100644 --- a/src/requests/quiz/server.tsx +++ b/src/requests/quiz/server.tsx @@ -3,7 +3,7 @@ import { API_ENDPOINTS } from '@/shared/configs/endpoint' import { httpServer } from '@/shared/lib/axios/http-server' -export const fetchTodayQuizSetId = async () => { +export const getTodayQuizSetId = async () => { try { const { data } = await httpServer.get( API_ENDPOINTS.QUIZ.GET.TODAY_SET @@ -14,7 +14,7 @@ export const fetchTodayQuizSetId = async () => { } } -export const fetchQuizSetById = async ({ +export const getQuizSetById = async ({ quizSetId, collectionId, quizSetType, diff --git a/src/shared/lib/tanstack-query/query-keys.ts b/src/shared/lib/tanstack-query/query-keys.ts index 79590648..5cc97adb 100644 --- a/src/shared/lib/tanstack-query/query-keys.ts +++ b/src/shared/lib/tanstack-query/query-keys.ts @@ -17,11 +17,11 @@ export const queries = createQueryKeyStore({ document: { list: (params?: { directoryId?: string; sortOption?: Document.Sort }) => ({ queryKey: [params], - queryFn: () => REQUEST.document.fetchDocuments(params), + queryFn: () => REQUEST.document.getDocuments(params), }), item: (documentId?: number) => ({ queryKey: [documentId], - queryFn: () => REQUEST.document.fetchDocumentDetail(documentId), + queryFn: () => REQUEST.document.getDocumentDetail(documentId), enabled: !!documentId, }), search: (requestBody: Document.Request.SearchDocuments) => ({ diff --git a/src/types/collection.d.ts b/src/types/collection.d.ts index 08a156dc..b109a1ff 100644 --- a/src/types/collection.d.ts +++ b/src/types/collection.d.ts @@ -18,6 +18,7 @@ declare global { declare namespace Collection { type Item = DeepRequired type Field = CollectionField + type ItemWithQuizzes = DeepRequired type SearchedCollection = DeepRequired diff --git a/src/types/quiz.d.ts b/src/types/quiz.d.ts index 6bc714d2..8206a858 100644 --- a/src/types/quiz.d.ts +++ b/src/types/quiz.d.ts @@ -22,7 +22,8 @@ declare global { declare namespace Quiz { type Item = QuizItem type List = QuizItem[] - type ItemWithMetadata = QuizItem & Metadata + type ItemWithMetadata = QuizWithMetadata + type ReplayType = ReplayQuizType type Type = QuizType type ReplayType = QuizType | 'RANDOM'