'use client' import { pageGridClass } from '@/components/layout/FeaturePage' import Link from 'next/link' import { useState } from 'react' import { BookOpen, Route } from 'lucide-react' import { useTranslation } from 'react-i18next' import { useLearningIndex } from '@/hooks/useLearningIndex' import { LearningCreateMenu } from './LearningCreateMenu' import { scopedUrl } from '@/lib/workspace-scope' import { bookRoute } from '@/lib/learning-routes' import { masterySessionRoute, masteryOpeningMessage, MASTERY_OPENING_SCOPE, } from '@/lib/mastery-mode' import { setPendingPrompt } from '@/lib/pending-prompt' import { learningTodos, allLearningActivity, type LearningKind, } from '@/lib/learning-dashboard' import { LearningShell, LearningEmptyState, LearningErrorState, LearningSkeleton, } from './LearningShell' import { LearningCard } from './LearningCard' import { LearningWays } from './LearningWays' import { LEARNING_SURFACES, learningSurface } from './surfaces' export function LearningDashboard() { const { t } = useTranslation() const { sources, failed, loading, retry } = useLearningIndex() const [kind, setKind] = useState('all') const [query, setQuery] = useState('') const [limit, setLimit] = useState(24) const selectedSurface = LEARNING_SURFACES.find(surface => surface.kind === kind) const todos = learningTodos(sources) const all = allLearningActivity(sources) const recent = all.filter(item => (kind === 'all' || item.kind === kind || (kind === 'reading' && item.kind === 'watching')) && item.title.toLocaleLowerCase().includes(query.toLocaleLowerCase())) return ( } >
{[{ kind: 'all', title: 'navigation.allLearning' }, ...LEARNING_SURFACES].map(surface => )}
{ setQuery(event.target.value); setLimit(24) }} className="ml-auto h-9 rounded-lg border border-border bg-transparent px-3 text-xs outline-none focus:border-ring" />
{selectedSurface && {t('Open')} {t(selectedSurface.title)} ↗} {failed.length > 0 && ( failed.includes(surface.kind)) .map(surface => t(surface.title)) .join(t('source list separator')), })} onRetry={retry} /> )} {loading ? ( ) : ( <> {(todos.reviews.length > 0 || todos.books.length > 0) && (

{t('What needs your attention')}

{todos.reviews.map(topic => ( } subtitle={t('{{count}} reviews due', { count: topic.reviews.filter(review => review.due).length, })} onClick={() => setPendingPrompt( masteryOpeningMessage('review', t, { dueTitles: topic.reviews .filter(review => review.due) .slice(0, 5) .map(review => review.knowledge_point_name), }), MASTERY_OPENING_SCOPE ) } /> ))} {todos.books.map(book => ( } subtitle={ <> {book.status === 'paused' ? t('Paused') : t('Compiling')} {book.status === 'paused' && book.metadata.pause_reason ? ` · ${book.metadata.pause_reason}` : ''} } /> ))}
)} {recent.length > 0 && (

{t('navigation.learningRecords')}

{recent.slice(0, limit).map(item => { const surface = learningSurface(item.kind) return ( } /> ) })}
)} {recent.length > limit && } {!all.length && failed.length === 0 && } {!recent.length && failed.length === 0 && ( )} )}
) }