Files
DeepTutor/web/components/learning/LearningShell.tsx
Bingxi Zhao (Frank) 28c11e2ae8 feat: update notes, chat interactions and workspace UI on preview
Remove course pages, APIs and the course_study capability. Add anchored note
threads and reviewed learning-block generation, queued and withdrawable chat
messages, quote attachments, side chats, and the calendar/favorites/navigation
updates.

Keep preview's existing backend architecture. Wire the new features through
its Python application and existing chat engine, retain legacy selected-text
requests, persist mid-turn messages in replay, and restore note context when
regenerating. Leave stored user data intact.

Validate frontend contracts, dependency boundaries, types, 1290 node tests,
840 rendered tests, lint, localization and the production build. Exercise
session/notes/API regressions, 53 chat-engine tests and 20 Python/native
integration tests with isolated runtime data.
2026-10-26 22:13:34 +08:00

133 lines
3.8 KiB
TypeScript

'use client'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { ArrowLeft, AlertCircle, BookOpen, RefreshCw, type LucideIcon } from 'lucide-react'
import type { ReactNode, Ref, UIEventHandler } from 'react'
import { useTranslation } from 'react-i18next'
import { LEARNING_HUB } from '@/lib/learning-routes'
import { FeaturePage, PageHeader } from '@/components/layout/FeaturePage'
import { useUiLayoutLabel } from '@/features/ui-layout/tokens'
import { LEARNING_SURFACES } from './surfaces'
/** The same page rhythm for the hub and each library; readers keep their full-screen layouts. */
export function LearningShell({
title,
subtitle,
action,
tabs,
children,
back = true,
className = '',
scrollRef,
onScroll,
icon,
}: {
title: ReactNode
subtitle: ReactNode
action?: ReactNode
tabs?: ReactNode
children: ReactNode
back?: boolean
className?: string
scrollRef?: Ref<HTMLElement>
onScroll?: UIEventHandler<HTMLElement>
/** Defaults to the icon of the learning surface this page belongs to. */
icon?: LucideIcon
}) {
const pathname = usePathname()
const learningLabel = useUiLayoutLabel('learning')
// usePathname is null outside the App Router (tests, embeds): no icon then.
const surfaceIcon = LEARNING_SURFACES.find(surface => pathname?.startsWith(surface.href))?.icon
return (
<FeaturePage
scrollRef={scrollRef}
onScroll={onScroll}
className={className}
>
{back && (
<Link
href={LEARNING_HUB}
className="dt-section-back mb-5 inline-flex items-center gap-1.5 text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)]"
>
<ArrowLeft size={14} />
{learningLabel}
</Link>
)}
<PageHeader title={title} description={subtitle} action={action} icon={icon ?? surfaceIcon ?? BookOpen} />
{tabs}
<div className={tabs ? 'mt-6' : ''}>{children}</div>
</FeaturePage>
)
}
export function LearningEmptyState({
title,
description,
action,
icon,
}: {
title: ReactNode
description?: ReactNode
action?: ReactNode
icon?: ReactNode
}) {
return (
<div className="my-6 rounded-xl border border-dashed border-[var(--border)] px-6 py-12 text-center">
{icon && (
<div className="mb-4 flex justify-center text-[var(--muted-foreground)]">{icon}</div>
)}
<h2 className="font-serif text-lg font-semibold">{title}</h2>
{description && (
<p className="mx-auto mt-2 max-w-lg text-sm leading-relaxed text-[var(--muted-foreground)]">
{description}
</p>
)}
{action && <div className="mt-5">{action}</div>}
</div>
)
}
export function LearningErrorState({
message,
onRetry,
}: {
message: ReactNode
onRetry?: () => void
}) {
const { t } = useTranslation()
return (
<div
role="alert"
className="my-4 flex flex-wrap items-center gap-3 rounded-xl border border-[var(--destructive)]/20 bg-[var(--destructive)]/5 p-4 text-sm"
>
<AlertCircle size={16} className="shrink-0 text-[var(--destructive)]" />
<span className="min-w-0 flex-1">{message}</span>
{onRetry && (
<button
type="button"
onClick={onRetry}
className="inline-flex items-center gap-1.5 font-medium hover:underline"
>
<RefreshCw size={14} />
{t('Retry')}
</button>
)}
</div>
)
}
export function LearningSkeleton({ count = 3 }: { count?: number }) {
const { t } = useTranslation()
return (
<div role="status" aria-label={t('Loading…')} className="my-6 grid gap-3" aria-busy="true">
{Array.from({ length: count }, (_, index) => (
<div
key={index}
className="h-20 animate-pulse rounded-xl border border-[var(--border)] bg-[var(--muted)]/60 motion-reduce:animate-none"
/>
))}
</div>
)
}