Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: retain navigation while refining partner and learning sidebars

Bingxi Zhao (Frank)2358b8d40746
diff --git a/artifacts/dito-preview/dt-exp-learning-navigation.png b/artifacts/dito-preview/dt-exp-learning-navigation.png
new file mode 100644
index 000000000..39be04b08
Binary files /dev/null and b/artifacts/dito-preview/dt-exp-learning-navigation.png differ
diff --git a/artifacts/dito-preview/dt-exp-partner-navigation.png b/artifacts/dito-preview/dt-exp-partner-navigation.png
new file mode 100644
index 000000000..59fc42f33
Binary files /dev/null and b/artifacts/dito-preview/dt-exp-partner-navigation.png differ
diff --git a/artifacts/dito-preview/dt-exp-qa.md b/artifacts/dito-preview/dt-exp-qa.md
index 8b92875d0..f174e0e20 100644
--- a/artifacts/dito-preview/dt-exp-qa.md
+++ b/artifacts/dito-preview/dt-exp-qa.md
@@ -53,3 +53,15 @@ Evidence: `dt-exp-practice.png`, `dt-exp-partners.png`, `dt-exp-writer.png` and
## Known limits
Model-backed generation, external channels and integrations require their normal configuration and were not live-tested in the isolated runtime. This iteration uses the existing chat/tool loop for Auto; it does not claim to add a new cross-capability autonomous planning engine. Mobile refinement was explicitly deferred by the user.
+
+
+## Sidebar refinement, 2026-10-12
+
+- Partner preview is capped at three avatars in one row; group preview is capped at two rows. Each section retains its total, full-list link and creation action. Conversations scroll independently beneath fixed headings, with title and owner on separate lines.
+- Verified against isolated API data with 8 partners, 6 groups and 36 conversations, including a 1280 × 600 desktop viewport. End/Home and Show more keep the sidebar at y=0; all 36 histories remain reachable. Searching Paul finds a partner outside the initial preview. Full-list anchors land on the respective partner/group sections.
+- Learning begins with one All learning row containing the original creation menu. Records show local-calendar groups and right-aligned relative timestamps. Last-active and creation-time ordering use the original data timestamps; search covers titles, workspace names and learning types. The sorting preference persists locally.
+- Verified creation-time ordering, search, Escape to clear, switching categories without losing ordering, and the original four learning creation options. Six isolated reading records exercise distinct creation/activity dates and all date groups.
+- Next dynamic components without a loading option can suspend to the outer workspace layout. Local Suspense boundaries now contain sidebar and feature loading; category switches use a transition and retain visited panels. Removed the repeated whole-category fade and chat greeting fade. Saved sidebar width restores before paint.
+- Recent navigation snapshots remain visible during background refresh and are cleared on authentication changes. A regression verifies that an in-flight response cannot restore the previous account cache after invalidation.
+- Validation: 152 Vitest files / 671 tests and 1,303 Node tests pass. Production build, type checking, i18n, dependency architecture and all existing route budgets pass. Targeted ESLint has no errors (existing logo-alt warnings remain).
+- Evidence: dt-exp-learning-navigation.png and dt-exp-partner-navigation.png. Test records remain isolated under /tmp/deeptutor-dt-exp-runtime; no production data schema or records were changed.
diff --git a/web/app/(workspace)/partners/page.tsx b/web/app/(workspace)/partners/page.tsx
index 65480e941..846afc800 100644
--- a/web/app/(workspace)/partners/page.tsx
+++ b/web/app/(workspace)/partners/page.tsx
@@ -60,9 +60,23 @@ export default function PartnersPage() {
};
}, []);
+ useEffect(() => {
+ if (loading) return;
+ const revealDirectorySection = () => {
+ const section = window.location.hash.slice(1);
+ if (section === "groups" || section === "partners") {
+ document.getElementById(section)?.scrollIntoView({ block: "start" });
+ }
+ };
+ revealDirectorySection();
+ window.addEventListener("hashchange", revealDirectorySection);
+ return () => window.removeEventListener("hashchange", revealDirectorySection);
+ }, [loading]);
+
return (
<FeaturePage>
<PageHeader
+ titleId="partners"
title={t("Partners")}
description={anyAssigned
? t("Your companions, plus the ones shared with you — each with its own soul, library, and channels.")
@@ -171,7 +185,7 @@ export default function PartnersPage() {
)}
{!loading && partners.length > 0 ? (
- <section className="mt-9 border-t border-[var(--border)] pt-7">
+ <section id="groups" className="mt-9 scroll-mt-7 border-t border-[var(--border)] pt-7">
<PageHeader
level={2}
title={t("Groups")}
diff --git a/web/app/globals.css b/web/app/globals.css
index 21e2894d5..4bde67a17 100644
--- a/web/app/globals.css
+++ b/web/app/globals.css
@@ -1474,7 +1474,7 @@ a[href^="#dt-locator-"]:hover {
.dt-category-bar.is-collapsed [role="tab"] > span:not(.dt-category-pill) { display: none; }
.dt-nav-search { width: 100%; margin-top: 8px; height: 32px; background: var(--background); border: 1px solid var(--border); border-radius: 7px; padding: 0 9px; font-size: 12px; outline: none; }
.dt-nav-search:focus { border-color: var(--ring); }
-.dt-category-content { padding: 0 8px 16px; animation: dt-shelf-enter 160ms ease-out; }
+.dt-category-content { padding: 0 8px 16px; }
.dt-navigation-section { margin-top: 17px; }
.dt-navigation-heading { display: flex; justify-content: space-between; align-items: center; min-height: 28px; margin-bottom: 4px; padding: 0 9px; font-size: 11px; font-weight: 600; color: var(--muted-foreground); }
.dt-navigation-row { display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 7px 9px; border-radius: 7px; text-align: left; color: var(--muted-foreground); font-size: 13px; transition: background-color 130ms, color 130ms; }
@@ -1482,13 +1482,50 @@ a[href^="#dt-locator-"]:hover {
.dt-navigation-row:hover, .dt-navigation-row.is-active { background: var(--accent); color: var(--foreground); }
.dt-navigation-row.is-active { font-weight: 500; }
.dt-navigation-empty { padding: 6px 9px; font-size: 11.5px; line-height: 1.7; color: var(--muted-foreground); }
-.dt-partner-roster { display: flex; flex-wrap: wrap; gap: 10px; padding: 5px 5px 10px; }
-.dt-partner-roster-item { display: flex; align-items: center; flex-direction: column; gap: 7px; padding: 6px 3px; width: 66px; border-radius: 10px; transition: background-color 140ms; }
-.dt-partner-roster-item:hover { background: var(--accent); }
-.dt-partner-roster-item > span:last-child { font-size: 11px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; max-width: 100%; color: var(--muted-foreground); }
-.dt-partner-add { display: flex; align-items: center; justify-content: center; width: 42px; height: 42px; border: 1px dashed var(--border); border-radius: 50%; color: var(--muted-foreground); }
+.dt-category-content-fixed { display: flex; flex-direction: column; height: 100%; min-height: 0; padding-bottom: 0; }
+.dt-category-content-fixed > .dt-navigation-section { flex-shrink: 0; margin-top: 4px; }
+.dt-partner-navigation { display: flex; flex: 1; flex-direction: column; min-height: 0; gap: 12px; padding-top: 14px; }
+.dt-partner-preview { flex-shrink: 0; }
+.dt-partner-navigation .dt-navigation-heading { flex-shrink: 0; }
+.dt-navigation-heading h2 { display: flex; align-items: center; min-width: 0; gap: 7px; font: inherit; }
+.dt-navigation-count { font-size: 10px; font-weight: 400; font-variant-numeric: tabular-nums; opacity: .7; }
+.dt-navigation-actions { display: flex; align-items: center; gap: 3px; }
+.dt-navigation-view-all { display: inline-flex; align-items: center; gap: 1px; padding: 4px; border-radius: 5px; font-size: 11px; font-weight: 400; white-space: nowrap; transition: background-color 140ms, color 140ms; }
+.dt-navigation-view-all:hover { background: var(--accent); color: var(--foreground); }
+.dt-partner-roster { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 2px 4px 0; }
+.dt-partner-roster-item { display: flex; align-items: center; flex-direction: column; gap: 6px; padding: 7px 3px; width: 100%; min-width: 0; border-radius: 8px; transition: background-color 140ms, color 140ms; }
+.dt-partner-roster-item:hover, .dt-partner-roster-item[aria-current="page"] { background: var(--accent); color: var(--foreground); }
+.dt-partner-roster-item > span:last-child { font-size: 11px; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; max-width: 100%; color: var(--muted-foreground); }
+.dt-partner-sessions { display: flex; flex: 1; flex-direction: column; min-height: 0; padding-top: 10px; border-top: 1px solid var(--border); }
+/* Keep the tooltip's visually hidden text inside this scroll container too. */
+.dt-partner-session-list { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 2px 0 8px; }
+.dt-partner-session-list .dt-navigation-row { display: grid; grid-template-columns: 18px minmax(0, 1fr); column-gap: 9px; row-gap: 2px; }
+.dt-partner-session-list .dt-navigation-row > svg { grid-row: 1 / 3; align-self: start; margin-top: 2px; }
+.dt-partner-session-list .dt-navigation-row > span { grid-column: 2; max-width: 100%; }
+.dt-partner-session-list .dt-navigation-row > span:last-child { font-size: 11px; font-weight: 400; }
+.dt-partner-session-list:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: 7px; }
+.dt-navigation-view-all:focus-visible, .dt-partner-roster-item:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.dt-new-conversation { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 40px; margin: 4px 3px 8px; border: 1px solid var(--border); border-radius: 22px; background: var(--background); font-size: 13px; font-weight: 500; box-shadow: 0 2px 5px rgb(0 0 0 / .025); transition: background-color 140ms, box-shadow 140ms; }
.dt-new-conversation:hover { background: var(--accent); box-shadow: 0 2px 8px rgb(0 0 0 / .045); }
@container (max-width: 240px) { .dt-category-bar [role="tab"] { padding: 0 4px; gap: 4px; } .dt-category-bar [role="tab"] > span:not(.dt-category-pill) { font-size: 12px; } }
-@keyframes dt-shelf-enter { from { opacity: .45; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
+
@media (prefers-reduced-motion: reduce) { .dt-category-content { animation: none; } .dt-product-sidebar * { transition-duration: 0ms !important; } }
+
+.dt-category-panel:not([hidden]) { display: flex; flex: 1; min-height: 0; flex-direction: column; }
+.dt-learning-navigation { display: flex; flex: 1; flex-direction: column; min-height: 0; padding-top: 14px; }
+.dt-learning-overview { display: flex; align-items: center; flex-shrink: 0; border-radius: 7px; padding-right: 4px; }
+.dt-learning-overview:hover, .dt-learning-overview.is-active { background: var(--accent); }
+.dt-learning-overview > a { display: flex; align-items: center; flex: 1; min-width: 0; gap: 9px; padding: 9px; font-size: 13px; font-weight: 500; }
+.dt-learning-overview > a:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: 7px; }
+.dt-learning-record-toolbar { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; padding: 12px 5px 4px; }
+.dt-learning-record-toolbar select { min-width: 0; max-width: 80%; padding: 4px; background: transparent; color: var(--muted-foreground); font-size: 11px; border-radius: 5px; cursor: pointer; }
+.dt-learning-record-toolbar select:hover { background: var(--accent); }
+.dt-learning-record-toolbar select:focus-visible { outline: 2px solid var(--ring); }
+.dt-learning-record-toolbar option { background: var(--background); color: var(--foreground); }
+.dt-learning-search { flex-shrink: 0; margin: 0 4px 8px; width: calc(100% - 8px); }
+.dt-learning-record-list { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 8px; }
+.dt-learning-record-list:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: 7px; }
+.dt-learning-time-group { margin-bottom: 14px; }
+.dt-learning-time-group > h2 { padding: 8px 9px 5px; font-size: 11px; font-weight: 500; color: var(--muted-foreground); }
+.dt-learning-time-group .dt-navigation-row { min-height: 38px; gap: 8px; }
+.dt-record-time { flex-shrink: 0; max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 400; color: var(--muted-foreground); opacity: .75; }
diff --git a/web/components/layout/AppShell.tsx b/web/components/layout/AppShell.tsx
index bd35c7bbb..d8d0eca66 100644
--- a/web/components/layout/AppShell.tsx
+++ b/web/components/layout/AppShell.tsx
@@ -6,6 +6,7 @@ import {
useContext,
useEffect,
useState,
+ Suspense,
} from "react";
import Image from "next/image";
import Link from "next/link";
@@ -129,7 +130,11 @@ export default function AppShell({ sidebar, children, homeHref = "/" }: AppShell
</Link>
</div>
- <div className="min-h-0 flex-1 overflow-hidden">{children}</div>
+ <div className="min-h-0 flex-1 overflow-hidden">
+ <Suspense fallback={<div aria-busy="true" className="h-full bg-[var(--background)]" />}>
+ {children}
+ </Suspense>
+ </div>
</main>
</div>
</SidebarDrawerContext.Provider>
diff --git a/web/components/sidebar/CategoryNavigation.tsx b/web/components/sidebar/CategoryNavigation.tsx
index 9e65fb117..e4d6b5aac 100644
--- a/web/components/sidebar/CategoryNavigation.tsx
+++ b/web/components/sidebar/CategoryNavigation.tsx
@@ -1,6 +1,6 @@
'use client'
-import { useId, useState, type ReactNode } from 'react'
+import { useId, useState, startTransition, type ReactNode } from 'react'
import dynamic from 'next/dynamic'
import { usePathname, useRouter } from 'next/navigation'
import { m, useReducedMotion } from 'framer-motion'
@@ -47,6 +47,7 @@ export function useCategoryNavigation() {
const categories = CATEGORIES.filter(item =>
navVisibleUnderPolicy(item.href, learningPolicy?.allowedSurfaces ?? null)
)
+ const [visited, setVisited] = useState<NavigationCategory[]>([])
const [selection, setSelection] = useState<{
pathname: string
category: NavigationCategory
@@ -58,13 +59,17 @@ export function useCategoryNavigation() {
return {
category,
categories,
+ visited,
query,
setQuery,
searchOpen,
setSearchOpen,
select: (next: NavigationCategory) => {
- setSelection({ pathname, category: next })
- setQuery('')
+ startTransition(() => {
+ setVisited(previous => [...new Set([...previous, category, next])])
+ setSelection({ pathname, category: next })
+ setQuery('')
+ })
},
allowedSurfaces: learningPolicy?.allowedSurfaces ?? null,
}
@@ -183,8 +188,7 @@ export function CategoryBody({
id="category-content"
role="tabpanel"
aria-labelledby={`category-${nav.category}`}
- className="dt-category-content"
- key={nav.category}
+ className={`dt-category-content ${['partners', 'learning'].includes(nav.category) ? 'dt-category-content-fixed' : ''}`}
>
{nav.category === 'home' && (
<>
@@ -212,9 +216,28 @@ export function CategoryBody({
{sessions}
</>
)}
- {nav.category === 'learning' && <LearningNavigation query={nav.query} sessions={sessions} />}
- {nav.category === 'partners' && <PartnerNavigation query={nav.query} />}
- {nav.category === 'resources' && <ResourcesNavigation query={nav.query} />}
+ {(nav.category === 'learning' || nav.visited.includes('learning')) && (
+ <div hidden={nav.category !== 'learning'} className="dt-category-panel">
+ <LearningNavigation
+ active={nav.category === 'learning'}
+ query={nav.category === 'learning' ? nav.query : ''}
+ sessions={sessions}
+ />
+ </div>
+ )}
+ {(nav.category === 'partners' || nav.visited.includes('partners')) && (
+ <div hidden={nav.category !== 'partners'} className="dt-category-panel">
+ <PartnerNavigation
+ active={nav.category === 'partners'}
+ query={nav.category === 'partners' ? nav.query : ''}
+ />
+ </div>
+ )}
+ {(nav.category === 'resources' || nav.visited.includes('resources')) && (
+ <div hidden={nav.category !== 'resources'}>
+ <ResourcesNavigation query={nav.category === 'resources' ? nav.query : ''} />
+ </div>
+ )}
{nav.searchOpen && matches(t('Settings'), nav.query) && (
<Section title={t('Settings')}>
<NavigationRow href="/settings" label={t('Settings')} icon={Settings} />
diff --git a/web/components/sidebar/LearningNavigation.tsx b/web/components/sidebar/LearningNavigation.tsx
index 6cda6ad60..9973583ad 100644
--- a/web/components/sidebar/LearningNavigation.tsx
+++ b/web/components/sidebar/LearningNavigation.tsx
@@ -1,39 +1,151 @@
'use client'
import { useTranslation } from 'react-i18next'
-import { NavigationRow, Section, Status, matches } from './NavigationPrimitives'
-import { useState, type ReactNode } from 'react'
-import { LayoutGrid, ChevronDown } from 'lucide-react'
+import { NavigationRow, Status, matches } from './NavigationPrimitives'
+import { useLayoutEffect, useState, type ReactNode } from 'react'
+import { usePathname } from 'next/navigation'
+import Link from 'next/link'
+import { LayoutGrid, ChevronDown, Search } from 'lucide-react'
import { LearningCreateMenu } from '@/components/learning/LearningCreateMenu'
import { learningSurface } from '@/components/learning/surfaces'
import { allLearningActivity } from '@/lib/learning-dashboard'
import { useLearningIndex } from '@/hooks/useLearningIndex'
+import { formatRelativeTime, getDayGroupKey, type DayGroupKey } from '@/lib/relative-time'
+import { browserStorage } from '@/shared/storage'
+import { useSidebarDrawer } from '@/components/layout/AppShell'
-export function LearningNavigation({ query, sessions }: { query: string; sessions: ReactNode }) {
- const { t } = useTranslation()
- const { sources, loading, failed, retry } = useLearningIndex()
+const SORT_KEY = 'deeptutor.navigation.learning.sort'
+const GROUP_LABELS: Record<DayGroupKey, string> = {
+ today: 'Today',
+ yesterday: 'Yesterday',
+ last_7_days: 'Last 7 days',
+ earlier: 'Earlier',
+}
+export function LearningNavigation({
+ query,
+ sessions,
+ active = true,
+}: {
+ query: string
+ sessions: ReactNode
+ active?: boolean
+}) {
+ const { t, i18n } = useTranslation()
+ const pathname = usePathname()
+ const drawer = useSidebarDrawer()
+ const { sources, loading, failed, retry } = useLearningIndex(active)
const [limit, setLimit] = useState(30)
- const rows = allLearningActivity(sources).filter(row =>
- matches(`${row.title} ${row.workspaceName ?? ''}`, query)
- )
+ const [sort, setSort] = useState<'updatedAt' | 'createdAt'>('updatedAt')
+ const [searchOpen, setSearchOpen] = useState(false)
+ const [localQuery, setLocalQuery] = useState('')
+ useLayoutEffect(() => {
+ if (browserStorage.readRaw('local', SORT_KEY) === 'createdAt') {
+ // Restore the view preference before paint, without changing any record.
+ // eslint-disable-next-line react-hooks/set-state-in-effect
+ setSort('createdAt')
+ }
+ }, [])
+ const rows = allLearningActivity(sources)
+ .filter(row => {
+ const label = `${row.title} ${row.workspaceName ?? ''} ${t(learningSurface(row.kind).title)}`
+ return matches(label, query) && matches(label, localQuery)
+ })
+ .sort((a, b) => b[sort] - a[sort] || a.key.localeCompare(b.key))
+ const grouped = Map.groupBy(rows.slice(0, limit), row => getDayGroupKey(row[sort]))
return (
- <>
- <Section title={t('navigation.learning')} action={<LearningCreateMenu compact />}>
- <NavigationRow href="/learning" label={t('navigation.allLearning')} icon={LayoutGrid} />
- </Section>
- <Section title={t('navigation.learningRecords')}>
+ <div className="dt-learning-navigation">
+ <div className={`dt-learning-overview ${pathname === '/learning' ? 'is-active' : ''}`}>
+ <Link
+ href="/learning"
+ prefetch={false}
+ aria-current={pathname === '/learning' ? 'page' : undefined}
+ onClick={event => {
+ if (!event.metaKey && !event.ctrlKey && !event.shiftKey) drawer?.close()
+ }}
+ >
+ <LayoutGrid size={18} strokeWidth={1.6} />
+ <span>{t('navigation.allLearning')}</span>
+ </Link>
+ <LearningCreateMenu compact />
+ </div>
+ <div className="dt-learning-record-toolbar">
+ <select
+ aria-label={t('navigation.sortLearning')}
+ value={sort}
+ onChange={event => {
+ const value = event.target.value as 'updatedAt' | 'createdAt'
+ setSort(value)
+ setLimit(30)
+ browserStorage.writeRaw('local', SORT_KEY, value)
+ }}
+ >
+ <option value="updatedAt">{t('navigation.lastActive')}</option>
+ <option value="createdAt">{t('navigation.createdTime')}</option>
+ </select>
+ <button
+ type="button"
+ className="dt-nav-icon"
+ aria-label={t('navigation.searchLearning')}
+ aria-expanded={searchOpen}
+ onClick={() => {
+ setSearchOpen(!searchOpen)
+ if (searchOpen) setLocalQuery('')
+ }}
+ >
+ <Search size={16} strokeWidth={1.6} />
+ </button>
+ </div>
+ {searchOpen && (
+ <input
+ autoFocus
+ className="dt-nav-search dt-learning-search"
+ aria-label={t('navigation.searchLearning')}
+ placeholder={t('navigation.searchLearning')}
+ value={localQuery}
+ onChange={event => {
+ setLocalQuery(event.target.value)
+ setLimit(30)
+ }}
+ onKeyDown={event => {
+ if (event.key === 'Escape') {
+ setLocalQuery('')
+ setSearchOpen(false)
+ }
+ }}
+ />
+ )}
+ <div
+ className="dt-learning-record-list"
+ role="region"
+ aria-label={t('navigation.learningRecords')}
+ tabIndex={0}
+ >
<Status loading={loading} error={failed.length > 0} retry={retry} />
- {rows.slice(0, limit).map(row => (
- <NavigationRow
- key={row.key}
- href={row.href}
- label={row.title}
- detail={row.workspaceName}
- icon={learningSurface(row.kind).icon}
- />
+ {[...grouped].map(([group, items]) => (
+ <section className="dt-learning-time-group" key={group}>
+ <h2>{t(GROUP_LABELS[group])}</h2>
+ {items.map(row => (
+ <NavigationRow
+ key={row.key}
+ href={row.href}
+ label={row.title}
+ detail={row.workspaceName}
+ icon={learningSurface(row.kind).icon}
+ trailing={
+ <time
+ className="dt-record-time"
+ dateTime={new Date(row[sort] * 1000).toISOString()}
+ title={new Date(row[sort] * 1000).toLocaleString(i18n.language)}
+ >
+ {formatRelativeTime(row[sort], i18n.language)}
+ </time>
+ }
+ />
+ ))}
+ </section>
))}
{!loading && !rows.length && !failed.length && (
<p className="dt-navigation-empty">
- {t(query ? 'navigation.noResults' : 'navigation.noLearning')}
+ {t(query || localQuery ? 'navigation.noResults' : 'navigation.noLearning')}
</p>
)}
{rows.length > limit && (
@@ -45,8 +157,8 @@ export function LearningNavigation({ query, sessions }: { query: string; session
{t('Show more')}
</button>
)}
- </Section>
- {sessions}
- </>
+ {sessions}
+ </div>
+ </div>
)
}
diff --git a/web/components/sidebar/NavigationPrimitives.tsx b/web/components/sidebar/NavigationPrimitives.tsx
index 28bf95718..4179ba164 100644
--- a/web/components/sidebar/NavigationPrimitives.tsx
+++ b/web/components/sidebar/NavigationPrimitives.tsx
@@ -15,6 +15,7 @@ export function NavigationRow({
detail,
active,
children,
+ trailing,
}: {
href: string
label: string
@@ -22,6 +23,7 @@ export function NavigationRow({
detail?: string
active?: boolean
children?: ReactNode
+ trailing?: ReactNode
}) {
const drawer = useSidebarDrawer()
const pathname = usePathname()
@@ -41,9 +43,10 @@ export function NavigationRow({
>
{children ?? (Icon && <Icon size={18} strokeWidth={1.6} />)}
<span className="min-w-0 flex-1 truncate">{label}</span>
- {detail && (
- <span className="max-w-[34%] truncate text-[11px] text-muted-foreground">{detail}</span>
- )}
+ {trailing ??
+ (detail && (
+ <span className="max-w-[34%] truncate text-[11px] text-muted-foreground">{detail}</span>
+ ))}
</Link>
</Tooltip>
)
diff --git a/web/components/sidebar/PartnerNavigation.tsx b/web/components/sidebar/PartnerNavigation.tsx
index 1115c88d6..82c1d0232 100644
--- a/web/components/sidebar/PartnerNavigation.tsx
+++ b/web/components/sidebar/PartnerNavigation.tsx
@@ -1,126 +1,173 @@
'use client'
import { useTranslation } from 'react-i18next'
-import { NavigationRow, Section, Status, matches } from './NavigationPrimitives'
+import { NavigationRow, Status, matches } from './NavigationPrimitives'
import { useState } from 'react'
import Link from 'next/link'
import { usePathname, useSearchParams } from 'next/navigation'
-import { Plus, ChevronDown, Users, MessageCircle } from 'lucide-react'
+import { Plus, ChevronDown, ChevronRight, Users, MessageCircle } from 'lucide-react'
import Tooltip from '@/shared/ui/Tooltip'
import PartnerAvatar from '@/components/partners/PartnerAvatar'
import { usePartnerNavigation } from '@/hooks/usePartnerNavigation'
import { partnerSessionHref } from '@/lib/navigation'
-export function PartnerNavigation({ query }: { query: string }) {
+export function PartnerNavigation({ query, active = true }: { query: string; active?: boolean }) {
const { t } = useTranslation()
const search = useSearchParams()
const pathname = usePathname()
- const { data, loading, error, retry } = usePartnerNavigation(true)
+ const { data, loading, error, retry } = usePartnerNavigation(active)
const [limit, setLimit] = useState(30)
+ const partners = data.partners.filter(row => matches(row.name, query))
+ const groups = data.groups.filter(row => matches(row.name, query))
const sessions = data.sessions.filter(row => matches(`${row.title} ${row.owner_name}`, query))
return (
- <>
- <Section
- title={t('navigation.partners')}
- action={
- <Link
- prefetch={false}
- href="/partners/new"
- aria-label={t('New partner')}
- className="dt-nav-icon"
- >
- <Plus size={16} />
- </Link>
- }
- >
+ <div className="dt-partner-navigation">
+ <section className="dt-partner-preview" aria-labelledby="partner-preview-title">
+ <div className="dt-navigation-heading">
+ <h2 id="partner-preview-title">
+ {t('navigation.partners')}{' '}
+ <span className="dt-navigation-count">{partners.length}</span>
+ </h2>
+ <div className="dt-navigation-actions">
+ <Link
+ prefetch={false}
+ href="/partners#partners"
+ aria-label={t('navigation.allPartners')}
+ className="dt-navigation-view-all"
+ >
+ {t('navigation.viewAll')}
+ <ChevronRight size={12} />
+ </Link>
+ <Link
+ prefetch={false}
+ href="/partners/new"
+ aria-label={t('New partner')}
+ className="dt-nav-icon"
+ >
+ <Plus size={16} />
+ </Link>
+ </div>
+ </div>
<div className="dt-partner-roster">
- {data.partners
- .filter(row => matches(row.name, query))
- .map(partner => (
- <Tooltip key={partner.partner_id} label={partner.name} side="right">
+ {partners.slice(0, 3).map(partner => {
+ const href = `/partners/${encodeURIComponent(partner.partner_id)}`
+ return (
+ <Tooltip
+ key={partner.partner_id}
+ label={partner.name}
+ side="right"
+ className="min-w-0"
+ >
<Link
- href={`/partners/${encodeURIComponent(partner.partner_id)}`}
+ href={href}
prefetch={false}
className="dt-partner-roster-item"
+ aria-current={pathname === href ? 'page' : undefined}
>
<PartnerAvatar
name={partner.name}
emoji={partner.emoji}
image={partner.avatar}
color={partner.color}
- size={42}
+ size={36}
/>
<span>{partner.name}</span>
</Link>
</Tooltip>
- ))}
- <Link prefetch={false} href="/partners/new" className="dt-partner-roster-item">
- <span className="dt-partner-add">
- <Plus size={22} strokeWidth={1.5} />
- </span>
- <span>{t('New partner')}</span>
- </Link>
+ )
+ })}
</div>
- <NavigationRow href="/partners" label={t('navigation.allPartners')} icon={Users} />
- </Section>
- <Status loading={loading} error={error || data.unavailable.length > 0} retry={retry} />
- <Section
- title={t('Groups')}
- action={
- data.partners.length >= 2 ? (
+ {!loading && !partners.length && (
+ <p className="dt-navigation-empty">
+ {t(query ? 'navigation.noResults' : 'No partners yet')}
+ </p>
+ )}
+ </section>
+ <section className="dt-partner-preview" aria-labelledby="group-preview-title">
+ <div className="dt-navigation-heading">
+ <h2 id="group-preview-title">
+ {t('Groups')} <span className="dt-navigation-count">{groups.length}</span>
+ </h2>
+ <div className="dt-navigation-actions">
<Link
prefetch={false}
- className="dt-nav-icon"
- href="/partners/groups/new"
- aria-label={t('New group')}
+ href="/partners#groups"
+ aria-label={t('navigation.allGroups')}
+ className="dt-navigation-view-all"
>
- <Plus size={16} />
+ {t('navigation.viewAll')}
+ <ChevronRight size={12} />
</Link>
- ) : null
- }
- >
- {data.groups
- .filter(row => matches(row.name, query))
- .map(group => (
- <NavigationRow
- key={group.group_id}
- href={`/partners/groups/${encodeURIComponent(group.group_id)}`}
- label={group.name}
- icon={Users}
- />
- ))}
- {!loading && !data.groups.length && (
- <p className="dt-navigation-empty">{t('navigation.noGroups')}</p>
- )}
- </Section>
- <Section title={t('navigation.partnerSessions')}>
- {sessions.slice(0, limit).map(row => {
- const href = partnerSessionHref(row)
- return (
- <NavigationRow
- key={`${row.kind}:${row.owner_id}:${row.session_key}`}
- href={href}
- label={row.title || t('New conversation')}
- detail={row.owner_name}
- icon={MessageCircle}
- active={pathname === href.split('?')[0] && search.get('session') === row.session_key}
- />
- )
- })}
- {!loading && !sessions.length && !error && (
+ {data.partners.length >= 2 && (
+ <Link
+ prefetch={false}
+ className="dt-nav-icon"
+ href="/partners/groups/new"
+ aria-label={t('New group')}
+ >
+ <Plus size={16} />
+ </Link>
+ )}
+ </div>
+ </div>
+ {groups.slice(0, 2).map(group => (
+ <NavigationRow
+ key={group.group_id}
+ href={`/partners/groups/${encodeURIComponent(group.group_id)}`}
+ label={group.name}
+ icon={Users}
+ />
+ ))}
+ {!loading && !groups.length && (
<p className="dt-navigation-empty">
- {t(query ? 'navigation.noResults' : 'navigation.noSessions')}
+ {t(query ? 'navigation.noResults' : 'navigation.noGroups')}
</p>
)}
- {sessions.length > limit && (
- <button
- className="dt-navigation-row w-full"
- onClick={() => setLimit(value => value + 30)}
- >
- <ChevronDown size={15} />
- {t('Show more')}
- </button>
- )}
- </Section>
- </>
+ </section>
+ <section className="dt-partner-sessions" aria-labelledby="partner-sessions-title">
+ <div className="dt-navigation-heading">
+ <h2 id="partner-sessions-title">
+ {t('navigation.partnerSessions')}{' '}
+ <span className="dt-navigation-count">{sessions.length}</span>
+ </h2>
+ </div>
+ <div
+ className="dt-partner-session-list"
+ tabIndex={0}
+ role="region"
+ aria-label={t('navigation.partnerSessions')}
+ >
+ <Status loading={loading} error={error || data.unavailable.length > 0} retry={retry} />
+ {sessions.slice(0, limit).map(row => {
+ const href = partnerSessionHref(row)
+ return (
+ <NavigationRow
+ key={`${row.kind}:${row.owner_id}:${row.session_key}`}
+ href={href}
+ label={row.title || t('New conversation')}
+ detail={row.owner_name}
+ icon={MessageCircle}
+ active={
+ pathname === href.split('?')[0] && search.get('session') === row.session_key
+ }
+ />
+ )
+ })}
+ {!loading && !sessions.length && !error && (
+ <p className="dt-navigation-empty">
+ {t(query ? 'navigation.noResults' : 'navigation.noSessions')}
+ </p>
+ )}
+ {sessions.length > limit && (
+ <button
+ className="dt-navigation-row w-full"
+ onClick={() => setLimit(value => value + 30)}
+ >
+ <ChevronDown size={15} />
+ {t('Show more')}
+ </button>
+ )}
+ </div>
+ </section>
+ </div>
)
}
diff --git a/web/components/sidebar/SidebarShell.tsx b/web/components/sidebar/SidebarShell.tsx
index 6cf2028b3..2b0b43364 100644
--- a/web/components/sidebar/SidebarShell.tsx
+++ b/web/components/sidebar/SidebarShell.tsx
@@ -10,6 +10,7 @@ import {
useEffect,
useRef,
useState,
+ Suspense,
type ReactNode,
type CSSProperties,
} from "react";
@@ -365,12 +366,14 @@ export function SidebarShell({
{homeSlot ? homeSlot(false) : <CategoryTabs nav={categoryNav} collapsed={false} />}
- {/* Modules and conversations share one scroll region below Home. */}
+ {/* Partner previews stay visible while their conversation list scrolls. */}
<div
ref={recentsScrollRef}
- className="min-h-0 flex-1 overflow-y-auto overscroll-contain pb-2"
+ className={`min-h-0 flex-1 ${!bodySlot && ["partners", "learning"].includes(categoryNav.category) ? "overflow-hidden" : "overflow-y-auto overscroll-contain pb-2"}`}
>
- {bodySlot ? bodySlot(false) : <CategoryBody nav={categoryNav} collapsed={false} sessions={sessionContent} />}
+ <Suspense fallback={<div aria-busy="true" className="mx-4 mt-5 h-3 w-28 rounded bg-muted" />}>
+ {bodySlot ? bodySlot(false) : <CategoryBody nav={categoryNav} collapsed={false} sessions={sessionContent} />}
+ </Suspense>
</div>
{/* Secondary nav + footer */}
diff --git a/web/features/chat/components/ChatWorkspace.tsx b/web/features/chat/components/ChatWorkspace.tsx
index 4cc1c54e6..35f607b66 100644
--- a/web/features/chat/components/ChatWorkspace.tsx
+++ b/web/features/chat/components/ChatWorkspace.tsx
@@ -155,7 +155,10 @@ import {
} from "@/lib/selection-tutor";
import { shouldReturnToChatAfterResearch } from "@/lib/deep-research-report";
-const HomeShortcuts = dynamic(() => import("@/components/chat/home/HomeShortcuts").then(module => module.HomeShortcuts));
+const HomeShortcuts = dynamic(
+ () => import("@/components/chat/home/HomeShortcuts").then(module => module.HomeShortcuts),
+ { loading: () => <div className="h-8" aria-busy="true" /> },
+);
const NotebookRecordPicker = dynamic(
() => import("@/components/notebook/NotebookRecordPicker"),
@@ -2500,7 +2503,7 @@ export default function ChatWorkspace() {
</div>
</div>
) : !hasMessages ? (
- <div className="flex w-full flex-1 min-h-0 items-end justify-center pb-14 animate-fade-in px-6">
+ <div className="flex w-full flex-1 min-h-0 items-end justify-center pb-14 px-6">
<div className="w-full max-w-[960px] flex flex-col items-center justify-center gap-4">
<img
src="/logo_black.png"
diff --git a/web/hooks/useLearningIndex.ts b/web/hooks/useLearningIndex.ts
index 0d5c38ae5..349c10644 100644
--- a/web/hooks/useLearningIndex.ts
+++ b/web/hooks/useLearningIndex.ts
@@ -1,37 +1,49 @@
'use client'
import { useCallback, useEffect, useState } from 'react'
+import { readClientCache, withClientCache } from '@/lib/client-cache'
import { usePathname } from 'next/navigation'
import { apiFetch, apiUrl } from '@/lib/api'
import { scopedUrl } from '@/lib/workspace-scope'
import { subscribeSessionChanges } from '@/lib/session-events'
import type { LearningKind, LearningSources } from '@/lib/learning-dashboard'
+const CACHE_KEY = 'navigation:learning-index'
+type LearningIndex = { sources: LearningSources; failed: LearningKind[] }
const EMPTY: LearningSources = { books: [], mastery: [], reading: [], watching: [], practice: [] }
export function useLearningIndex(enabled = true) {
const pathname = usePathname()
- const [sources, setSources] = useState<LearningSources>(EMPTY)
- const [failed, setFailed] = useState<LearningKind[]>([])
- const [loading, setLoading] = useState(true)
+ const [sources, setSources] = useState<LearningSources>(
+ () => readClientCache<LearningIndex>(CACHE_KEY)?.sources ?? EMPTY
+ )
+ const [failed, setFailed] = useState<LearningKind[]>(
+ () => readClientCache<LearningIndex>(CACHE_KEY)?.failed ?? []
+ )
+ const [loading, setLoading] = useState(() => !readClientCache<LearningIndex>(CACHE_KEY))
const [revision, setRevision] = useState(0)
const retry = useCallback(() => setRevision(value => value + 1), [])
useEffect(() => {
if (!enabled) return
let alive = true
let busy = false
- const controller = new AbortController()
const refresh = async () => {
if (busy || document.visibilityState === 'hidden') return
busy = true
try {
- const response = await apiFetch(apiUrl(scopedUrl('/api/dashboard/learning-index', '')), {
- signal: AbortSignal.any([controller.signal, AbortSignal.timeout(20000)]),
- })
- if (!response.ok) throw new Error('Learning index unavailable')
- const payload = (await response.json()) as {
- sources: LearningSources
- failed: LearningKind[]
- }
+ const payload = await withClientCache(
+ CACHE_KEY,
+ async () => {
+ const response = await apiFetch(
+ apiUrl(scopedUrl('/api/dashboard/learning-index', '')),
+ {
+ signal: AbortSignal.timeout(20000),
+ }
+ )
+ if (!response.ok) throw new Error('Learning index unavailable')
+ return (await response.json()) as LearningIndex
+ },
+ { force: true }
+ )
if (alive) {
// Keep readable collections during a transient partial outage.
setSources(
@@ -63,7 +75,6 @@ export function useLearningIndex(enabled = true) {
const timer = window.setInterval(refresh, 30000)
return () => {
alive = false
- controller.abort()
unsubscribe()
window.clearInterval(timer)
window.removeEventListener('focus', refresh)
diff --git a/web/hooks/usePartnerNavigation.ts b/web/hooks/usePartnerNavigation.ts
index 0a90e04cd..9e6b81fcc 100644
--- a/web/hooks/usePartnerNavigation.ts
+++ b/web/hooks/usePartnerNavigation.ts
@@ -1,5 +1,6 @@
'use client'
import { useCallback, useEffect, useState } from 'react'
+import { readClientCache, withClientCache } from '@/lib/client-cache'
import { usePathname } from 'next/navigation'
import { apiFetch, apiUrl } from '@/lib/api'
import { subscribeSessionChanges } from '@/lib/session-events'
@@ -22,15 +23,19 @@ export interface PartnerNavigationData {
sessions: PartnerNavigationSession[]
unavailable: string[]
}
+const CACHE_KEY = 'navigation:partners'
export function usePartnerNavigation(enabled: boolean) {
const pathname = usePathname()
- const [data, setData] = useState<PartnerNavigationData>({
- partners: [],
- groups: [],
- sessions: [],
- unavailable: [],
- })
- const [loading, setLoading] = useState(true)
+ const [data, setData] = useState<PartnerNavigationData>(
+ () =>
+ readClientCache<PartnerNavigationData>(CACHE_KEY) ?? {
+ partners: [],
+ groups: [],
+ sessions: [],
+ unavailable: [],
+ }
+ )
+ const [loading, setLoading] = useState(() => !readClientCache<PartnerNavigationData>(CACHE_KEY))
const [error, setError] = useState(false)
const [revision, setRevision] = useState(0)
const retry = useCallback(() => setRevision(value => value + 1), [])
@@ -38,16 +43,21 @@ export function usePartnerNavigation(enabled: boolean) {
if (!enabled) return
let alive = true
let busy = false
- const controller = new AbortController()
const refresh = async () => {
if (busy || document.visibilityState === 'hidden') return
busy = true
try {
- const response = await apiFetch(apiUrl('/api/partners/navigation'), {
- signal: AbortSignal.any([controller.signal, AbortSignal.timeout(20000)]),
- })
- if (!response.ok) throw new Error('Partner navigation unavailable')
- const next = (await response.json()) as PartnerNavigationData
+ const next = await withClientCache(
+ CACHE_KEY,
+ async () => {
+ const response = await apiFetch(apiUrl('/api/partners/navigation'), {
+ signal: AbortSignal.timeout(20000),
+ })
+ if (!response.ok) throw new Error('Partner navigation unavailable')
+ return (await response.json()) as PartnerNavigationData
+ },
+ { force: true }
+ )
if (alive) {
setData(next)
setError(false)
@@ -66,7 +76,6 @@ export function usePartnerNavigation(enabled: boolean) {
document.addEventListener('visibilitychange', refresh)
return () => {
alive = false
- controller.abort()
unsubscribe()
window.clearInterval(timer)
window.removeEventListener('focus', refresh)
diff --git a/web/hooks/useSidebarResize.ts b/web/hooks/useSidebarResize.ts
index 78642cd96..cf9652083 100644
--- a/web/hooks/useSidebarResize.ts
+++ b/web/hooks/useSidebarResize.ts
@@ -2,6 +2,7 @@
import {
useEffect,
+ useLayoutEffect,
useRef,
useState,
type KeyboardEvent,
@@ -33,7 +34,7 @@ export function useSidebarResize(
} | null>(null);
const width = clampWidth(preferredWidth, max);
- useEffect(() => {
+ useLayoutEffect(() => {
const stored = Number(browserStorage.readRaw("local", storageKey));
if (Number.isFinite(stored) && stored > 0) {
// Hydrate after mount to keep the initial render consistent with SSR.
diff --git a/web/lib/auth.ts b/web/lib/auth.ts
index e12194021..8eb738a16 100644
--- a/web/lib/auth.ts
+++ b/web/lib/auth.ts
@@ -1,3 +1,4 @@
+import { invalidateClientCache } from "./client-cache";
import { apiFetch, apiUrl, setRuntimeAuthEnabled } from "@/lib/api";
// Auth state is resolved at runtime from the backend (`/api/auth/status`),
@@ -38,6 +39,7 @@ let cachedAuthStatus: { value: AuthStatus | null; expiresAt: number } | null =
null;
export function invalidateAuthStatusCache(): void {
+ invalidateClientCache("navigation:");
authStatusRequest = null;
cachedAuthStatus = null;
}
diff --git a/web/lib/client-cache.ts b/web/lib/client-cache.ts
index 380fb4f63..bb1b2c10f 100644
--- a/web/lib/client-cache.ts
+++ b/web/lib/client-cache.ts
@@ -13,6 +13,14 @@ interface CacheOptions {
force?: boolean;
}
+/** A synchronous, workspace-scoped snapshot for views re-entered during SPA navigation. */
+export function readClientCache<T>(key: string): T | undefined {
+ if (typeof window === "undefined") return undefined;
+ const cached = clientCache.get(`${key}:workspace=${activeWorkspaceId()}`) as
+ CacheEntry<T> | undefined;
+ return cached && cached.expiresAt > Date.now() ? cached.data : undefined;
+}
+
export async function withClientCache<T>(
key: string,
loader: () => Promise<T>,
@@ -37,7 +45,7 @@ export async function withClientCache<T>(
}
const promise = loader()
- .then((value) => {
+ .then(value => {
// Invalidated or superseded requests must not repopulate stale data.
if (clientCache.get(key)?.promise === promise) {
clientCache.set(key, {
@@ -47,12 +55,13 @@ export async function withClientCache<T>(
}
return value;
})
- .catch((error) => {
+ .catch(error => {
if (clientCache.get(key)?.promise === promise) clientCache.delete(key);
throw error;
});
clientCache.set(key, {
+ data: cached?.data,
promise,
expiresAt: now + ttlMs,
});
diff --git a/web/lib/learning-dashboard.ts b/web/lib/learning-dashboard.ts
index e2ad741b8..81d2ff569 100644
--- a/web/lib/learning-dashboard.ts
+++ b/web/lib/learning-dashboard.ts
@@ -1,9 +1,14 @@
-import { scopedUrl } from "@/lib/workspace-scope";
+import { scopedUrl } from '@/lib/workspace-scope'
import type { Book } from '@/lib/book-types'
import type { MasteryTopic } from '@/lib/learning-api'
import type { ReadingWorkspace } from '@/lib/reading-workspace-api'
import type { SessionSummary } from '@/lib/session-api'
-import { bookRoute, masteryTopicRoute, readingCollectionRoute, practiceRoute } from '@/lib/learning-routes'
+import {
+ bookRoute,
+ masteryTopicRoute,
+ readingCollectionRoute,
+ practiceRoute,
+} from '@/lib/learning-routes'
import { sessionRoute } from '@/lib/mastery-session'
export type LearningKind = 'books' | 'mastery' | 'reading' | 'watching' | 'practice'
@@ -21,6 +26,7 @@ export interface LearningActivity {
title: string
href: string
updatedAt: number
+ createdAt: number
workspaceName?: string
progress?: number
}
@@ -34,47 +40,58 @@ export function isWatchingSession(session: SessionSummary): boolean {
export function allLearningActivity(sources: LearningSources): LearningActivity[] {
return [
...(sources.practice ?? []).map(entry => ({
- key: `practice:${entry.content_workspace_id || ""}:${entry.id}`,
+ key: `practice:${entry.content_workspace_id || ''}:${entry.id}`,
kind: 'practice' as const,
title: entry.question,
- href: scopedUrl(practiceRoute(new URLSearchParams({ question: String(entry.id) }), ""), entry.content_workspace_id || ""),
+ href: scopedUrl(
+ practiceRoute(new URLSearchParams({ question: String(entry.id) }), ''),
+ entry.content_workspace_id || ''
+ ),
updatedAt: entry.updated_at || entry.created_at,
+ createdAt: entry.created_at || entry.updated_at,
workspaceName: entry.content_workspace_name,
})),
...sources.books.map(book => ({
- key: `book:${book.content_workspace_id || ""}:${book.id}`,
+ key: `book:${book.content_workspace_id || ''}:${book.id}`,
kind: 'books' as const,
title: book.title,
- href: scopedUrl(bookRoute(book.id, null, ""), book.content_workspace_id || ""),
+ href: scopedUrl(bookRoute(book.id, null, ''), book.content_workspace_id || ''),
updatedAt: book.updated_at,
+ createdAt: book.created_at || book.updated_at,
workspaceName: book.content_workspace_name,
progress: (book.reading?.percent ?? 0) / 100,
})),
...sources.mastery
.filter(topic => topic.metadata.status === 'active')
.map(topic => ({
- key: `topic:${topic.content_workspace_id || ""}:${topic.path_id}`,
+ key: `topic:${topic.content_workspace_id || ''}:${topic.path_id}`,
kind: 'mastery' as const,
title: topic.name || topic.metadata.goal,
- href: scopedUrl(masteryTopicRoute(topic.path_id, ""), topic.content_workspace_id || ""),
+ href: scopedUrl(masteryTopicRoute(topic.path_id, ''), topic.content_workspace_id || ''),
updatedAt: topic.updated_at,
+ createdAt: topic.metadata.created_at || topic.updated_at,
workspaceName: topic.content_workspace_name,
progress: topic.map.counts.total ? topic.map.counts.mastered / topic.map.counts.total : 0,
})),
...sources.reading.map(workspace => ({
- key: `reading:${workspace.content_workspace_id || ""}:${workspace.workspace_id}`,
+ key: `reading:${workspace.content_workspace_id || ''}:${workspace.workspace_id}`,
kind: 'reading' as const,
title: workspace.title,
- href: scopedUrl(readingCollectionRoute(workspace.workspace_id, ""), workspace.content_workspace_id || ""),
+ href: scopedUrl(
+ readingCollectionRoute(workspace.workspace_id, ''),
+ workspace.content_workspace_id || ''
+ ),
updatedAt: workspace.updated_at,
+ createdAt: workspace.created_at || workspace.updated_at,
workspaceName: workspace.content_workspace_name,
})),
...sources.watching.filter(isWatchingSession).map(session => ({
- key: `session:${session.content_workspace_id || ""}:${session.session_id}`,
+ key: `session:${session.content_workspace_id || ''}:${session.session_id}`,
kind: 'watching' as const,
title: session.title,
href: sessionRoute(session),
updatedAt: session.updated_at,
+ createdAt: session.created_at || session.updated_at,
})),
].sort((a, b) => b.updatedAt - a.updatedAt || a.key.localeCompare(b.key))
}
diff --git a/web/locales/de/app.json b/web/locales/de/app.json
index 6a5ff49bd..b71a14770 100644
--- a/web/locales/de/app.json
+++ b/web/locales/de/app.json
@@ -5521,7 +5521,12 @@
"navigation.search": "Search this section",
"navigation.workspace": "Workspace",
"navigation.newChat": "New conversation",
+ "navigation.sortLearning": "Lerneinträge sortieren",
+ "navigation.lastActive": "Zuletzt aktiv",
+ "navigation.createdTime": "Erstellt am",
"navigation.allLearning": "All learning",
+ "navigation.viewAll": "Alle",
+ "navigation.allGroups": "Alle Gruppen",
"navigation.allPartners": "All partners",
"navigation.allResources": "All resources",
"navigation.learningRecords": "Your learning",
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index 8851e9d73..e71c67ae3 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -5521,7 +5521,12 @@
"navigation.search": "Search this section",
"navigation.workspace": "Workspace",
"navigation.newChat": "New conversation",
+ "navigation.sortLearning": "Sort learning records",
+ "navigation.lastActive": "Last active",
+ "navigation.createdTime": "Created time",
"navigation.allLearning": "All learning",
+ "navigation.viewAll": "All",
+ "navigation.allGroups": "All groups",
"navigation.allPartners": "All partners",
"navigation.allResources": "All resources",
"navigation.learningRecords": "Your learning",
diff --git a/web/locales/fr/app.json b/web/locales/fr/app.json
index 0091155cd..305840078 100644
--- a/web/locales/fr/app.json
+++ b/web/locales/fr/app.json
@@ -5901,7 +5901,12 @@
"navigation.search": "Search this section",
"navigation.workspace": "Workspace",
"navigation.newChat": "New conversation",
+ "navigation.sortLearning": "Trier les activités",
+ "navigation.lastActive": "Dernière activité",
+ "navigation.createdTime": "Date de création",
"navigation.allLearning": "All learning",
+ "navigation.viewAll": "Tout",
+ "navigation.allGroups": "Tous les groupes",
"navigation.allPartners": "All partners",
"navigation.allResources": "All resources",
"navigation.learningRecords": "Your learning",
diff --git a/web/locales/pl/app.json b/web/locales/pl/app.json
index f65da6a26..78a57e9c2 100644
--- a/web/locales/pl/app.json
+++ b/web/locales/pl/app.json
@@ -5537,7 +5537,12 @@
"navigation.search": "Search this section",
"navigation.workspace": "Workspace",
"navigation.newChat": "New conversation",
+ "navigation.sortLearning": "Sortuj naukę",
+ "navigation.lastActive": "Ostatnia aktywność",
+ "navigation.createdTime": "Data utworzenia",
"navigation.allLearning": "All learning",
+ "navigation.viewAll": "Wszystkie",
+ "navigation.allGroups": "Wszystkie grupy",
"navigation.allPartners": "All partners",
"navigation.allResources": "All resources",
"navigation.learningRecords": "Your learning",
diff --git a/web/locales/uk/app.json b/web/locales/uk/app.json
index f74be8440..7346ced7d 100644
--- a/web/locales/uk/app.json
+++ b/web/locales/uk/app.json
@@ -5537,7 +5537,12 @@
"navigation.search": "Search this section",
"navigation.workspace": "Workspace",
"navigation.newChat": "New conversation",
+ "navigation.sortLearning": "Сортувати навчання",
+ "navigation.lastActive": "Остання активність",
+ "navigation.createdTime": "Час створення",
"navigation.allLearning": "All learning",
+ "navigation.viewAll": "Усі",
+ "navigation.allGroups": "Усі групи",
"navigation.allPartners": "All partners",
"navigation.allResources": "All resources",
"navigation.learningRecords": "Your learning",
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 3830f4416..142aba5c0 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -5521,7 +5521,12 @@
"navigation.search": "搜索当前栏目",
"navigation.workspace": "工作台",
"navigation.newChat": "新对话",
+ "navigation.sortLearning": "学习记录排序",
+ "navigation.lastActive": "最后一次活跃",
+ "navigation.createdTime": "创建时间",
"navigation.allLearning": "全部学习",
+ "navigation.viewAll": "全部",
+ "navigation.allGroups": "全部群组",
"navigation.allPartners": "全部伙伴",
"navigation.allResources": "全部资料",
"navigation.learningRecords": "学习记录",
diff --git a/web/tests/app-shell-suspense.spec.tsx b/web/tests/app-shell-suspense.spec.tsx
new file mode 100644
index 000000000..d56e12add
--- /dev/null
+++ b/web/tests/app-shell-suspense.spec.tsx
@@ -0,0 +1,20 @@
+import { act, render, screen } from '@testing-library/react'
+import { lazy, Suspense, type ComponentType } from 'react'
+import { expect, it, vi } from 'vitest'
+import AppShell from '@/components/layout/AppShell'
+
+vi.mock('next/navigation', () => ({ usePathname: () => '/learning' }))
+vi.mock('next/image', () => ({ default: () => null }))
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }))
+vi.mock('@/hooks/useDevice', () => ({ useDevice: () => ({ isMobile: false }) }))
+
+it('keeps the application navigation visible while a feature module loads', async () => {
+ let finish!: (module: { default: ComponentType }) => void
+ const Feature = lazy(() => new Promise<{ default: ComponentType }>(resolve => { finish = resolve }))
+ render(<Suspense fallback={<p>Whole page replaced</p>}><AppShell sidebar={<nav>Persistent navigation</nav>}><Feature /></AppShell></Suspense>)
+ expect(screen.getByText('Persistent navigation')).toBeVisible()
+ expect(screen.queryByText('Whole page replaced')).not.toBeInTheDocument()
+ await act(async () => finish({ default: () => <p>Loaded feature</p> }))
+ expect(screen.getByText('Loaded feature')).toBeVisible()
+ expect(screen.getByText('Persistent navigation')).toBeVisible()
+})
diff --git a/web/tests/learning-navigation.spec.tsx b/web/tests/learning-navigation.spec.tsx
new file mode 100644
index 000000000..2b57a529c
--- /dev/null
+++ b/web/tests/learning-navigation.spec.tsx
@@ -0,0 +1,41 @@
+import { fireEvent, render, screen, within } from '@testing-library/react'
+import { beforeEach, expect, it, vi } from 'vitest'
+import { LearningNavigation } from '@/components/sidebar/LearningNavigation'
+
+vi.mock('next/navigation', () => ({ usePathname: () => '/learning', useSearchParams: () => new URLSearchParams() }))
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key, i18n: { language: 'en' } }) }))
+vi.mock('@/components/learning/LearningCreateMenu', () => ({ LearningCreateMenu: () => <button>Create learning</button> }))
+vi.mock('@/components/layout/AppShell', () => ({ useSidebarDrawer: () => null }))
+vi.mock('@/hooks/useLearningIndex', () => ({ useLearningIndex: () => ({
+ loading: false, failed: [], retry: vi.fn(), sources: {
+ books: [], mastery: [], reading: [], watching: [], practice: [
+ { id: 1, question: 'Older material, recently studied', created_at: 100, updated_at: 900, content_workspace_id: 'physics' },
+ { id: 2, question: 'Newly created material', created_at: 800, updated_at: 800, content_workspace_id: '' },
+ ],
+ },
+}) }))
+beforeEach(() => localStorage.clear())
+
+it('sorts by creation independently of activity and retains the preference', () => {
+ const view = render(<LearningNavigation query="" sessions={null} />)
+ const records = () => within(screen.getByRole('region', { name: 'navigation.learningRecords' })).getAllByRole('link')
+ expect(records()[0]).toHaveTextContent('Older material')
+ fireEvent.change(screen.getByRole('combobox', { name: 'navigation.sortLearning' }), { target: { value: 'createdAt' } })
+ expect(records()[0]).toHaveTextContent('Newly created material')
+ expect(records()[1]).toHaveAttribute('href', '/learning/practice?question=1&dt_workspace=physics')
+ view.unmount()
+ render(<LearningNavigation query="" sessions={null} />)
+ expect(records()[0]).toHaveTextContent('Newly created material')
+})
+
+it('searches records without discarding the rest of the library', () => {
+ render(<LearningNavigation query="" sessions={null} />)
+ fireEvent.click(screen.getByRole('button', { name: 'navigation.searchLearning' }))
+ const input = screen.getByRole('textbox', { name: 'navigation.searchLearning' })
+ fireEvent.change(input, { target: { value: 'recently' } })
+ const list = within(screen.getByRole('region', { name: 'navigation.learningRecords' }))
+ expect(list.getAllByRole('link')).toHaveLength(1)
+ expect(list.getByRole('link')).toHaveTextContent('Older material')
+ fireEvent.keyDown(input, { key: 'Escape' })
+ expect(list.getAllByRole('link')).toHaveLength(2)
+})
diff --git a/web/tests/workspace-navigation.spec.tsx b/web/tests/workspace-navigation.spec.tsx
index 01f4e2b28..bd9ba3029 100644
--- a/web/tests/workspace-navigation.spec.tsx
+++ b/web/tests/workspace-navigation.spec.tsx
@@ -63,3 +63,22 @@ it('does not let invalidated in-flight requests overwrite fresh cache entries',
await old
expect(await withClientCache('scope-regression', async () => 'unexpected')).toBe('fresh')
})
+
+it('keeps navigation snapshots during refresh and clears them on account changes', async () => {
+ const { readClientCache } = await import('@/lib/client-cache')
+ const { invalidateAuthStatusCache } = await import('@/lib/auth')
+ const key = 'navigation:retained-view'
+ window.history.replaceState(null, '', '/learning?dt_workspace=first')
+ await withClientCache(key, async () => 'first account')
+ let finish!: (value: string) => void
+ const refresh = withClientCache(key, () => new Promise<string>(resolve => { finish = resolve }), { force: true })
+ expect(readClientCache(key)).toBe('first account')
+ window.history.replaceState(null, '', '/learning?dt_workspace=second')
+ expect(readClientCache(key)).toBeUndefined()
+ window.history.replaceState(null, '', '/learning?dt_workspace=first')
+ invalidateAuthStatusCache()
+ expect(readClientCache(key)).toBeUndefined()
+ finish('outdated account response')
+ await refresh
+ expect(readClientCache(key)).toBeUndefined()
+})