Files
DeepTutor/web/components/sidebar/PageBar.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

69 lines
2.7 KiB
TypeScript

'use client'
import { usePathname } from 'next/navigation'
import { useTranslation } from 'react-i18next'
import { useAuthStatus } from '@/hooks/useAuthStatus'
import { useDevice } from '@/hooks/useDevice'
import { useCapabilityFilter } from '@/features/capabilities/useCapabilityCatalog'
import { usePageSlotRef } from '@/components/layout/PageChrome'
import { FeatureCrumb } from '@/components/layout/LocationCrumbs'
import { locatePage, pageSections } from './page-sections'
function useShelves() {
const { t, i18n } = useTranslation()
const { learningPolicy } = useAuthStatus()
const isAvailable = useCapabilityFilter()
return pageSections({
t,
zh: (i18n?.language ?? '').startsWith('zh'),
allowedSurfaces: learningPolicy?.allowedSurfaces ?? null,
isAvailable,
})
}
/**
* The shelf and feature entry for a feature page, for views that draw the
* crumbs in a toolbar of their own (see `OWN_HEADER`).
*/
export function useShelfFeature(href: string) {
const sections = useShelves()
for (const section of sections) {
const page = section.pages.find(entry => entry.href === href)
if (page) return { section, page }
}
return null
}
/**
* The top of every page: 「feature / the one use of it that is open」 on the
* left and the page's own actions on the right. The feature opens onto the
* other features of its sidebar shelf; the page hands up the rest — its
* instance crumb (see `InstanceCrumb`), its meta and actions — through
* `PageBarSlot`. Rendered by the route layouts above the page, so pages
* need no wiring and their own "back to section" links become redundant
* (modern.css hides them). Which workspace this is shows only in the
* sidebar: every page here belongs to the current one.
*/
export function PageBar() {
const { t } = useTranslation()
const pathname = usePathname() ?? ''
const { isMobile } = useDevice()
const instanceRef = usePageSlotRef('instance')
const metaRef = usePageSlotRef('meta')
const actionsRef = usePageSlotRef('actions')
const located = locatePage(pathname, useShelves())
// Phones have their own top row; without the bar, headers keep everything.
if (!located || isMobile) return null
// On the feature page itself the bar is the header; under a detail page
// it locates it, and the page keeps its own title and meta.
const exact = located.page.href === pathname
return (
<nav aria-label={t('navigation.location')} className="dt-page-bar" data-exact={exact || undefined}>
<FeatureCrumb section={located.section} page={located.page} />
<div ref={instanceRef} className="dt-page-bar-instance" />
{exact && <div ref={metaRef} className="dt-page-bar-meta" />}
<div ref={actionsRef} className="dt-page-bar-actions" />
</nav>
)
}