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-document
  • Loading branch information
rabyeoljji committed Nov 23, 2024
2 parents 30fa96c + 8d9944f commit e5ac1a4
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 94 deletions.
134 changes: 134 additions & 0 deletions src/features/write/components/create-quiz-drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
'use client'

import Icon from '@/shared/components/custom/icon'
import { Button } from '@/shared/components/ui/button'
import { Drawer, DrawerContent, DrawerTitle, DrawerTrigger } from '@/shared/components/ui/drawer'
import { Slider } from '@/shared/components/ui/slider'
import Text from '@/shared/components/ui/text'
import { cn } from '@/shared/lib/utils'
import { useState } from 'react'

interface Props {
handleCreateDocument: (params: { quizType: Quiz.Type; star: number }) => void
}

const CreateQuizDrawer = ({ handleCreateDocument }: Props) => {
const totalQuizCount = 40
const [selectedQuizCount, setSelectedQuizCount] = useState(10)
const [selectedQuizType, setSelectedQuizType] = useState<Quiz.Type>('MULTIPLE_CHOICE')

const handleSliderChange = (value: number[]) => {
const newCount = Math.round((value[0] / 100) * totalQuizCount)
setSelectedQuizCount(newCount)
}

const handleClickQuizType = (quizType: Quiz.Type) => {
setSelectedQuizType(quizType)
}

return (
<Drawer>
<DrawerTrigger asChild>
<Button variant={'largeRound'} colors={'primary'} className="flex-center h-[52px] w-full">
퀴즈 만들기
</Button>
</DrawerTrigger>

<DrawerContent className="mx-auto flex h-full max-h-[90dvh] max-w-mobile flex-col pb-[136px] *:px-4">
<DrawerTitle>
<Text typography="title3" className="pt-5">
원하는 유형과 문제 수를 선택해주세요
</Text>
</DrawerTitle>

<div className="flex items-center gap-2 pt-[38px]">
<button
className={cn(
'border-default relative flex h-[136px] flex-1 flex-col justify-end rounded-[16px] border p-4',
selectedQuizType === 'MULTIPLE_CHOICE' &&
'border-border-focused bg-background-base-03'
)}
onClick={() => handleClickQuizType('MULTIPLE_CHOICE')}
>
<Icon name="multiple-quiz-icon" className="absolute top-[11px] h-[57px] w-[89.5px]" />
<Text typography="subtitle2-bold">객관식</Text>
<Text typography="text2-medium" color="sub">
4개 선택지 중 정답 고르기
</Text>
</button>
<button
className={cn(
'border-default relative flex h-[136px] flex-1 flex-col justify-end rounded-[16px] border p-4',
selectedQuizType === 'MIX_UP' && 'border-border-focused bg-background-base-03'
)}
onClick={() => handleClickQuizType('MIX_UP')}
>
<Icon
name="o-x-quiz-icon"
className="absolute left-[10px] top-[18px] h-[57px] w-[89.5px]"
/>
<Text typography="subtitle2-bold">O/X</Text>
<Text typography="text2-medium" color="sub">
참과 거짓 판단하기
</Text>
</button>
</div>

<div className="my-7 h-px w-full bg-border-divider" />

<div className="flex-1 text-center">
<Text typography="text1-medium" color="sub">
만들 문제
</Text>
<Text typography="title1" color="accent" className="mt-2">
{selectedQuizCount} 문제
</Text>
<Slider
defaultValue={[25]}
value={[(selectedQuizCount / totalQuizCount) * 100]}
onValueChange={handleSliderChange}
className="mt-4"
/>
<div className="mt-2.5 flex justify-between">
<Text typography="text2-medium" color="sub">
{selectedQuizCount} 문제
</Text>
<Text typography="text2-medium" color="sub">
{totalQuizCount} 문제
</Text>
</div>
</div>

<div className="absolute bottom-0 h-[100px] w-full pt-3">
<Text
typography="text2-medium"
color="sub"
className="absolute right-1/2 top-[-8px] translate-x-1/2 text-center"
>
현재 나의 별: <span className="text-text-secondary">16개</span>
</Text>
<Button
variant={'largeRound'}
colors={'special'}
className="flex w-full gap-1 text-white"
onClick={() =>
handleCreateDocument({ quizType: selectedQuizType, star: selectedQuizCount })
}
>
<div>퀴즈 생성하기</div>
<div className="flex items-center gap-1 rounded-full bg-[#D3DCE4]/20 px-2 py-px">
<span>
<Icon name="star" />
</span>
<Text typography="text1-medium" color="primary-inverse">
{selectedQuizCount}
</Text>
</div>
</Button>
</div>
</DrawerContent>
</Drawer>
)
}

export default CreateQuizDrawer
39 changes: 21 additions & 18 deletions src/features/write/pages/write-document-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,46 @@ import Icon from '@/shared/components/custom/icon'
import Text from '@/shared/components/ui/text'
import dynamic from 'next/dynamic'
import FixedBottom from '@/shared/components/custom/fixed-bottom'
import { Button } from '@/shared/components/ui/button'
import { useCreateDocument } from '@/requests/document/hooks'
import { MAX_CHARACTERS, MIN_CHARACTERS } from '@/features/document/config'
import { useDirectoryContext } from '@/features/directory/contexts/directory-context'
import CreateQuizDrawer from '../components/create-quiz-drawer'
import { useRouter } from 'next/navigation'

const Editor = dynamic(() => import('../components/editor'), {
ssr: false,
})

const WriteDocumentPage = () => {
const router = useRouter()

const { selectedDirectory } = useDirectoryContext()
const [title, setTitle] = useState('')
const [content, setContent] = useState('')

const { mutate: createDocumentMutate } = useCreateDocument()

const handleCreateDocument = () => {
const handleCreateDocument = ({ quizType, star }: { quizType: Quiz.Type; star: number }) => {
// TODO: validation
if (!selectedDirectory) {
return
}

createDocumentMutate({
directoryId: selectedDirectory.id,
documentName: title,
file: content,
quizType: 'MULTIPLE_CHOICE',
star: 5,
documentType: 'TEXT',
})
createDocumentMutate(
{
directoryId: selectedDirectory.id,
documentName: title,
file: content,
quizType,
star,
documentType: 'TEXT',
},
{
onSuccess: ({ id }) => {
router.push(`/document/${id}`)
},
}
)
}

return (
Expand Down Expand Up @@ -67,14 +77,7 @@ const WriteDocumentPage = () => {
<Editor handleContentChange={(value: string) => setContent(value)} />

<FixedBottom className="px-[20px]">
<Button
variant={'largeRound'}
colors={'primary'}
className="flex-center h-[52px] w-full"
onClick={handleCreateDocument}
>
퀴즈 만들기
</Button>
<CreateQuizDrawer handleCreateDocument={handleCreateDocument} />
</FixedBottom>
</div>
)
Expand Down
77 changes: 1 addition & 76 deletions src/types/quiz.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,61 +150,11 @@ declare namespace Quiz {
type Item = CombineQuiz
type List = CombineQuiz[]
type ItemWithMetadata = QuizWithMetadata
type QuizType = QuizType
type Type = QuizType
type Record = QuizRecord
type Result = UpdateQuizResultPayload['quizzes'][number]

declare namespace Request {
/** GET /api/v2/today-quiz-info
* 오늘의 퀴즈 현황
*/
type GetTodayInfo = void

/** GET /api/v2/quizzes
* 생성된 모든 퀴즈 가져오기(전체 문서)
*/
type GetAllQuizzes = void

/** GET /api/v2/quizzes/{quiz_set_id}/quiz-record
* 퀴즈 세트에 대한 상세 기록
*/
type GetQuizSetRecord = void

/** GET /api/v2/quizzes/quiz-records
* 전체 퀴즈 기록
*/
type GetQuizRecords = void

/** GET /api/v2/quiz-sets/{quiz_set_id}
* quizSet_id로 퀴즈 가져오기
*/
type GetQuizSet = void

/** GET /api/v2/quiz-sets/today
* 오늘의 퀴즈 세트 정보 가져오기
*/
type GetTodayQuizSet = void

/** GET /api/v2/quiz-analysis
* 퀴즈 분석
*/
type GetQuizAnalysis = void

/** GET /api/v2/documents/{document_id}/review-pick
* document_id로 복습 pick 가져오기
*/
type GetReviewPick = void

/** GET /api/v2/documents/{document_id}/quizzes
* document_id에 해당하는 모든 퀴즈 가져오기
*/
type GetDocumentQuizzes = void

/** GET /api/v2/documents/{document_id}/download-quiz
* 퀴즈 다운로드
*/
type DownloadQuiz = void

/** PATCH /api/v2/quiz/result
* 퀴즈 결과 업데이트
*/
Expand All @@ -214,16 +164,6 @@ declare namespace Quiz {
* 사용자가 생성한 문서에서 직접 퀴즈 생성(랜덤, OX, 객관식)
*/
type CreateQuizzes = CreateQuizzesPayload

/** DELETE /api/v2/quizzes/{quiz_id}/delete-quiz
* 퀴즈 삭제
*/
type DeleteQuiz = void

/** DELETE /api/v2/quizzes/{quiz_id}/delete-invalid-quiz
* 잘못된 퀴즈 삭제
*/
type DeleteInvalidQuiz = void
}

declare namespace Response {
Expand Down Expand Up @@ -281,20 +221,5 @@ declare namespace Quiz {
* 퀴즈 결과 업데이트
*/
type UpdateQuizResult = UpdateQuizResultResponse

/** POST /api/v2/quizzes/documents/{document_id}/create-quizzes
* 사용자가 생성한 문서에서 직접 퀴즈 생성(랜덤, OX, 객관식)
*/
type CreateQuizzes = void

/** DELETE /api/v2/quizzes/{quiz_id}/delete-quiz
* 퀴즈 삭제
*/
type DeleteQuiz = void

/** DELETE /api/v2/quizzes/{quiz_id}/delete-invalid-quiz
* 잘못된 퀴즈 삭제
*/
type DeleteInvalidQuiz = void
}
}

0 comments on commit e5ac1a4

Please sign in to comment.