mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:09:24 +08:00
Collections vs workspaces: a workspace holds many collections, and a collection's files and reading conversations live in the workspace it was created in. The library now shows collections as folders grouped under their workspace, and creating one asks which workspace it goes into. - Folder page at /learning/reading/folders/[folderId]: breadcrumb, files, the collection's conversations, and "Start reading" that opens the whole folder in the reader. The reader's back link returns to it. - Collections carry a user-picked color (new `color` column, migrated); tones are --folder-* tokens with dark variants. - One shared "New collection" / "Edit collection" dialog with consistent type sizes. - Selection popover gains AI actions; results land as cards at the foot of the companion. Read-aloud is a single header toggle. - The three ⋯ menus (collection, document, conversation) merge into one. - Outline toggle moves to the left and starts closed; navigator has Outline / Annotations tabs. - Reading conversations live in the main sidebar (with a page-shaped idle mark) instead of a history dropdown in the companion. - Fix sidebar rows never showing a selected state (bg-[var(--background)]/60 compiled to nothing). - Composer floats over the conversation (no divider, bottom fade); the toolbar wraps by content instead of splitting under 420px.
66 lines
3.5 KiB
TypeScript
66 lines
3.5 KiB
TypeScript
import { activeWorkspaceId, scopedUrl } from "@/lib/workspace-scope";
|
|
|
|
const inWorkspace = (path: string, id: string) => id ? scopedUrl(path, id) : path;
|
|
|
|
/** Canonical browser routes for personalized learning. Never use these for API requests. */
|
|
export const LEARNING_HUB = '/learning'
|
|
export const BOOKS_HOME = `${LEARNING_HUB}/books`
|
|
export const PRACTICE_HOME = `${LEARNING_HUB}/practice`
|
|
export const MASTERY_HOME = `${LEARNING_HUB}/mastery`
|
|
export const READING_HOME = `${LEARNING_HUB}/reading`
|
|
export const READING_MATERIALS = `${READING_HOME}/materials`
|
|
export const WATCHING_HOME = `${LEARNING_HUB}/watching`
|
|
|
|
const segment = (value: string) => encodeURIComponent(value.trim())
|
|
|
|
export function bookRoute(bookId?: string | null, pageId?: string | null, workspaceId = activeWorkspaceId()): string {
|
|
if (!bookId?.trim()) return inWorkspace(BOOKS_HOME, workspaceId)
|
|
const book = `${BOOKS_HOME}/${segment(bookId)}`
|
|
return inWorkspace(pageId?.trim() ? `${book}/pages/${segment(pageId)}` : book, workspaceId)
|
|
}
|
|
export function masteryTopicRoute(pathId: string, workspaceId = activeWorkspaceId()): string {
|
|
return inWorkspace(`${MASTERY_HOME}/${segment(pathId)}`, workspaceId)
|
|
}
|
|
export function masterySessionsRoute(pathId: string, query?: URLSearchParams, workspaceId = activeWorkspaceId()): string {
|
|
const suffix = query?.toString()
|
|
return inWorkspace(`${masteryTopicRoute(pathId, "")}/sessions${suffix ? `?${suffix}` : ''}`, workspaceId)
|
|
}
|
|
export function masterySessionRoute(pathId: string, sessionId: string, workspaceId = activeWorkspaceId()): string {
|
|
return inWorkspace(`${masterySessionsRoute(pathId, undefined, "")}/${segment(sessionId)}`, workspaceId)
|
|
}
|
|
export function readingCollectionRoute(workspaceId: string, contentWorkspaceId = activeWorkspaceId()): string {
|
|
return inWorkspace(`${READING_HOME}/${segment(workspaceId)}`, contentWorkspaceId)
|
|
}
|
|
/** A collection seen as a folder: its files, its conversations, and the way into reading. */
|
|
export function readingFolderRoute(workspaceId: string, contentWorkspaceId = activeWorkspaceId()): string {
|
|
return inWorkspace(`${READING_HOME}/folders/${segment(workspaceId)}`, contentWorkspaceId)
|
|
}
|
|
export function readingSessionRoute(workspaceId: string, sessionId: string, contentWorkspaceId = activeWorkspaceId()): string {
|
|
return inWorkspace(`${readingCollectionRoute(workspaceId, "")}/sessions/${segment(sessionId)}`, contentWorkspaceId)
|
|
}
|
|
export function watchingRoute(sessionId?: string | null, workspaceId = activeWorkspaceId()): string {
|
|
return inWorkspace(sessionId?.trim() ? `${WATCHING_HOME}/${segment(sessionId)}` : WATCHING_HOME, workspaceId)
|
|
}
|
|
/** Follows native history binding as well as router navigation; rejects malformed URLs. */
|
|
export function readingSessionIdFromPath(pathname: string): string | null {
|
|
const path = pathname.split(/[?#]/, 1)[0]
|
|
if (!path.startsWith(`${READING_HOME}/`)) return null
|
|
const parts = path.slice(READING_HOME.length + 1).split('/')
|
|
if (!parts[0] || parts[1] !== 'sessions' || !parts[2] || parts.slice(3).some(Boolean)) return null
|
|
try {
|
|
return decodeURIComponent(parts[2]).trim() || null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function practiceRoute(query?: URLSearchParams, workspaceId = activeWorkspaceId()): string {
|
|
const suffix = query?.toString();
|
|
return inWorkspace(`${PRACTICE_HOME}${suffix ? `?${suffix}` : ""}`, workspaceId);
|
|
}
|
|
|
|
export function questionBankRoute(query?: URLSearchParams, workspaceId = activeWorkspaceId()): string {
|
|
const suffix = query?.toString();
|
|
return inWorkspace(`/space/questions${suffix ? `?${suffix}` : ""}`, workspaceId);
|
|
}
|