Files
DeepTutor/web/components/reading/workspace-menu-context.ts
Bingxi Zhao (Frank) 53436f8190 feat(reading): collections as colored folders; rework reader interactions
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.
2026-09-23 18:59:17 +08:00

61 lines
1.7 KiB
TypeScript

"use client";
import type { LucideIcon } from "lucide-react";
import { createContext, useContext, useEffect } from "react";
/**
* One entry in the workspace's single ⋯ menu.
*
* The reader, the companion and the collection each had a ⋯ of their own —
* three identical icons a hand's width apart, and a learner looking for
* "export" had to open all three. The panels still own their actions; they
* hand them up here, and the top bar lists them in one place.
*/
export interface WorkspaceMenuItem {
key: string;
icon: LucideIcon;
label: string;
hint?: string;
/** A setting that is on (shown with a check), not an action. */
active?: boolean;
disabled?: boolean;
spinning?: boolean;
onSelect: () => void;
}
export type WorkspaceMenuSection = "material" | "conversation";
export interface WorkspaceMenuHost {
register: (
section: WorkspaceMenuSection,
items: WorkspaceMenuItem[] | null,
) => void;
}
export const WorkspaceMenuContext = createContext<WorkspaceMenuHost | null>(
null,
);
/**
* Publish a panel's menu items to the workspace's ⋯ menu.
*
* Returns whether a workspace is listening: a panel rendered on its own keeps
* its own ⋯, since nothing else would show these actions. `items` must be
* memoised, or every render re-registers and re-renders the workspace.
*/
export function useWorkspaceMenuSection(
section: WorkspaceMenuSection,
items: WorkspaceMenuItem[] | null,
): boolean {
const host = useContext(WorkspaceMenuContext);
useEffect(() => {
if (!host) return;
host.register(section, items);
}, [host, items, section]);
useEffect(() => {
if (!host) return;
return () => host.register(section, null);
}, [host, section]);
return host !== null;
}