Skip to content
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

feat: random quiz #314

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/app/(routes)/quiz/random/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import RandomQuizView from '@/features/quiz/screen/random-quiz-view'
import { getBookmarkedCollections } from '@/requests/collection/server'
import { getDirectories } from '@/requests/directory/server'

const RandomQuiz = async () => {
const bookmarkedCollections = await getBookmarkedCollections()
const directories = await getDirectories()

return <RandomQuizView collections={bookmarkedCollections.collections} directories={[]} />
const directoriesHasDocuments = directories.directories.filter(
(directory) => directory.documentCount > 0
)

return <RandomQuizView directories={directoriesHasDocuments} />
}

export default RandomQuiz
22 changes: 11 additions & 11 deletions src/features/category/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
type Category = {
code: Collection.Field
id: Collection.Field
name: string
emoji: string
}

export const CATEGORIES: Category[] = [
{
code: 'IT',
id: 'IT',
name: 'IT·프로그래밍',
emoji: '🤖',
},
{
code: 'LAW',
id: 'LAW',
name: '법률·정치',
emoji: '📖',
},
{
code: 'BUSINESS_ECONOMY',
id: 'BUSINESS_ECONOMY',
name: '경제·경영',
emoji: '💰',
},
{
code: 'SOCIETY_POLITICS',
id: 'SOCIETY_POLITICS',
name: '사회·정치',
emoji: '⚖️',
},
{
code: 'LANGUAGE',
id: 'LANGUAGE',
name: '언어',
emoji: '💬',
},
{
code: 'MEDICINE_PHARMACY',
id: 'MEDICINE_PHARMACY',
name: '의학·약학',
emoji: '🩺',
},
{
code: 'ART',
id: 'ART',
name: '예술',
emoji: '🎨',
},
{
code: 'SCIENCE_ENGINEERING',
id: 'SCIENCE_ENGINEERING',
name: '과학·공학',
emoji: '🔬',
},
{
code: 'HISTORY_PHILOSOPHY',
id: 'HISTORY_PHILOSOPHY',
name: '역사·철학',
emoji: '📜',
},
{
code: 'OTHER',
id: 'OTHER',
name: '기타',
emoji: '♾️',
},
Expand Down
3 changes: 1 addition & 2 deletions src/features/collection/components/collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const Collection = ({
}: Props) => {
const { mutate: bookmarkMutate } = useBookmarkMutation()

const categoryLabel =
CATEGORIES.find((categoryItem) => categoryItem.code === category)?.name ?? ''
const categoryLabel = CATEGORIES.find((categoryItem) => categoryItem.id === category)?.name ?? ''

return (
<div className={cn('min-w-[166px]', className)}>
Expand Down
8 changes: 4 additions & 4 deletions src/features/collection/components/create-collection-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const CreateCollectionForm = () => {
const [emoji, setEmoji] = useState('🥹')
const [title, setTitle] = useState('')
const [description, setDescription] = useState('')
const [categoryCode, setCategoryCode] = useState(CATEGORIES[0]?.code ?? 'IT')
const [categoryCode, setCategoryCode] = useState(CATEGORIES[0]?.id ?? 'IT')

const { data: directoryQuizzesData, isLoading: directoryQuizzesLoading } =
useDirectoryQuizzes(selectedDirectoryId)
Expand Down Expand Up @@ -225,7 +225,7 @@ const CreateCollectionForm = () => {
<DrawerTrigger>
<div className="rounded-full bg-background-base-02 px-[14px] py-[5px]">
<CategoryTag
title={CATEGORIES.find((category) => category.code === categoryCode)?.name ?? ''}
title={CATEGORIES.find((category) => category.id === categoryCode)?.name ?? ''}
/>
</div>
</DrawerTrigger>
Expand All @@ -235,10 +235,10 @@ const CreateCollectionForm = () => {
</DrawerHeader>
<div className="flex flex-col gap-2 p-4">
{CATEGORIES.map((category) => (
<DrawerClose key={category.code}>
<DrawerClose key={category.id}>
<CategoryTag
title={category.name}
onClick={() => setCategoryCode(category.code)}
onClick={() => setCategoryCode(category.id)}
/>
</DrawerClose>
))}
Expand Down
4 changes: 2 additions & 2 deletions src/features/quiz/screen/quiz-view/components/quiz-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QUIZ_ANIMATION_DURATION } from '@/features/quiz/config'
import { cn } from '@/shared/lib/utils'

interface QuizOptionsProps {
quiz: Quiz.Item
quiz: Quiz.Item | Quiz.RandomItem
currentResult: Quiz.Result | null
onAnswer: (params: { id: number; isRight: boolean; choseAnswer: string }) => void
className?: HTMLElement['className']
Expand All @@ -31,7 +31,7 @@ const QuizOptions = ({ quiz, currentResult, onAnswer, className }: QuizOptionsPr
if (quiz.quizType === 'MULTIPLE_CHOICE') {
return (
<motion.div
className={cn('flex flex-col gap-[12px]', className)}
className={cn('flex flex-col gap-[12px] w-full', className)}
variants={container}
initial="hidden"
animate="show"
Expand Down
Loading
Loading