- {isBookmarkedLoading || isLoading ? (
+
+ {isLoading ? (
) : (
- collectionsData?.collections.map((collection) => {
- const isBookmarked = Boolean(
- bookmarkedCollections?.collections.some(
- (bookmarkedCollection) => bookmarkedCollection.id === collection.id
- )
- )
- const multipleChoiceCount =
- collection.quizzes?.filter((quiz) => quiz.quizType === 'MULTIPLE_CHOICE').length ?? 0
- const oxCount =
- collection.quizzes?.filter((quiz) => quiz.quizType === 'MIX_UP').length ?? 0
-
- return (
- (
+
+
- }
/>
- )
- })
+
+ ))
)}
>
diff --git a/src/features/collection/components/my-collection.tsx b/src/features/collection/components/my-collection.tsx
index 8d24e61e..4867fd53 100644
--- a/src/features/collection/components/my-collection.tsx
+++ b/src/features/collection/components/my-collection.tsx
@@ -2,42 +2,51 @@
import Text from '@/shared/components/ui/text'
import { cn } from '@/shared/lib/utils'
-import { useState } from 'react'
import Collection from './collection'
import CollectionList from './collection-list'
import Link from 'next/link'
import Icon from '@/shared/components/custom/icon'
-import StartQuizDrawer from './start-quiz-drawer'
import { useBookmarkedCollections, useMyCollections } from '@/requests/collection/hooks'
import Loading from '@/shared/components/custom/loading'
import { SwitchCase } from '@/shared/components/custom/react/switch-case'
+import { useRouter, useSearchParams } from 'next/navigation'
+import { useScrollPosition } from '@/shared/hooks/use-scroll-position'
-const tabs = [
+const sort = [
{ key: 'create-collection', label: '만든 컬렉션' },
{ key: 'save-collection', label: '보관한 컬렉션' },
] as const
+type TabType = (typeof sort)[number]['key']
+
const MyCollection = () => {
- const [activeTab, setActiveTab] = useState<'create-collection' | 'save-collection'>(
- 'create-collection'
- )
+ const router = useRouter()
+ const searchParams = useSearchParams()
+ const activeTab = (searchParams.get('sort') as TabType) || 'create-collection'
+
+ const scrollContainerRef = useScrollPosition({ pageKey: 'my-collection' })
const { data: myCollectionsData, isLoading: isMyCollectionLoading } = useMyCollections()
const { data: bookmarkedCollectionsData, isLoading: isBookmarkedCollectionLoading } =
useBookmarkedCollections()
- const { data: bookmarkedCollections, isLoading: isBookmarkedLoading } = useBookmarkedCollections()
+
+ const handleTabChange = (tab: TabType) => {
+ const params = new URLSearchParams(searchParams)
+ params.set('sort', tab)
+ router.replace(`?${params.toString()}`)
+ }
return (
<>
- {tabs.map((tab) => (
+ {sort.map((tab) => (