Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:picktoss/pick-toss-next into fea…
Browse files Browse the repository at this point in the history
…t-search

# Conflicts:
#	src/requests/document/hooks.ts
  • Loading branch information
rabyeoljji committed Dec 10, 2024
2 parents e9c1206 + 07a4f70 commit f793682
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/app/(routes)/document/[id]/(main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 (
<main className="min-h-screen">
Expand Down
8 changes: 4 additions & 4 deletions src/app/(routes)/main/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
18 changes: 12 additions & 6 deletions src/app/(routes)/quiz/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -13,25 +14,30 @@ interface Props {
// 문서 퀴즈일 경우
documentName?: string
directoryEmoji?: string
// 콜렉션 퀴즈일 경우
collectionId?: string
// 콜렉션 퀴즈일 경우 (id는 params로 받음)
collectionName?: string
collectionEmoji?: string
}
}

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),
Expand Down
4 changes: 3 additions & 1 deletion src/features/collection/components/detail-info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ const DetailInfo = ({ id }: Props) => {
)}

<FixedBottom>
<Link href="#">
<Link
href={`/quiz/${collectionData.id}?quizType=collection&collectionName=${collectionData.name}&collectionEmoji=${collectionData.emoji}`}
>
{/* 이동 /quiz/[id] - searchParams로 collectionId, createdAt, collectionName, collectionEmoji 넣어서 */}
<Button className="w-full">퀴즈 시작하기</Button>
</Link>
Expand Down
2 changes: 1 addition & 1 deletion src/features/quiz/components/replay-quiz-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ReplayQuizDrawer = ({

const { mutate: replayDocumentQuizMutate } = useReplayDocumentQuiz()

const [quizType, setQuizType] = useState<ReplayQuizType>('RANDOM')
const [quizType, setQuizType] = useState<Quiz.ReplayType>('RANDOM')
const [quizCount, setQuizCount] = useState(savedQuizCount)

const minQuizCount = savedQuizCount > 5 ? 5 : 1
Expand Down
11 changes: 11 additions & 0 deletions src/requests/collection/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Collection.ItemWithQuizzes>(
API_ENDPOINTS.COLLECTION.GET.INFO(id)
)
return data
} catch (error) {
throw error
}
}

/** server에서만 사용 */
export const getBookmarkedCollections = async () => {
try {
Expand Down
7 changes: 3 additions & 4 deletions src/requests/document/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/requests/document/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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),
})
}

Expand Down
8 changes: 3 additions & 5 deletions src/requests/document/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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<Document.DetailItem>(
Expand Down
4 changes: 2 additions & 2 deletions src/requests/quiz/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Quiz.Response.GetTodayQuizSet>(
API_ENDPOINTS.QUIZ.GET.TODAY_SET
Expand All @@ -14,7 +14,7 @@ export const fetchTodayQuizSetId = async () => {
}
}

export const fetchQuizSetById = async ({
export const getQuizSetById = async ({
quizSetId,
collectionId,
quizSetType,
Expand Down
4 changes: 2 additions & 2 deletions src/shared/lib/tanstack-query/query-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down
1 change: 1 addition & 0 deletions src/types/collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare global {
declare namespace Collection {
type Item = DeepRequired<components['schemas']['CollectionDto']>
type Field = CollectionField
type ItemWithQuizzes = DeepRequired<components['schemas']['GetSingleCollectionResponse']>

type SearchedCollection = DeepRequired<components['schemas']['IntegratedSearchCollectionDto']>

Expand Down
3 changes: 2 additions & 1 deletion src/types/quiz.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f793682

Please sign in to comment.