'use client' import { scopedUrl } from "@/lib/workspace-scope"; import { LearningShell } from '@/components/learning/LearningShell' import { READING_HOME, READING_MATERIALS } from '@/lib/learning-routes' import Link from 'next/link' import { Plus } from 'lucide-react' import { useEffect, useState, type ReactNode } from 'react' import { useTranslation } from 'react-i18next' import { learningLibrary } from '@/lib/learning-library' /** * Header shared by the two reading views. Immersive Reading has exactly two * places to be — the collections you read in, and the library of everything * you have uploaded — so they sit under one title as two tabs rather than * behind a second sidebar. */ export function LibraryShell({ view, collectionCount, materialCount, actionLabel, onAction, scopeChip, children, }: { view: 'collections' | 'materials' collectionCount?: number materialCount?: number actionLabel: string onAction: () => void /** Rendered beside the title when this visit belongs to one course. */ scopeChip?: ReactNode children: ReactNode }) { const { t } = useTranslation() // Each view knows its own count; the other one is fetched once so the tabs // never show a blank where a number belongs. const [otherCount, setOtherCount] = useState(null) useEffect(() => { let alive = true const missing = view === 'collections' ? materialCount : collectionCount if (missing !== undefined) return void (async () => { try { const value = view === 'collections' ? (await learningLibrary('materials')).items.length : (await learningLibrary('reading')).items.length if (alive) setOtherCount(value) } catch { // A missing tab count is not worth an error state; the tab still works. } })() return () => { alive = false } }, [collectionCount, materialCount, view]) const collections = collectionCount ?? (view === 'materials' ? (otherCount ?? undefined) : undefined) const materials = materialCount ?? (view === 'collections' ? (otherCount ?? undefined) : undefined) return ( {actionLabel} } tabs={ } > {children} ) } function ViewTab({ href, label, count, active, }: { href: string label: string count?: number active: boolean }) { return ( {label} {typeof count === 'number' && ( {count} )} ) }