mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:39:47 +08:00
Below 768px the reader header converges to back, title + chapter, bookmark and more: forward moves into the more menu (also when the workspace hosts it), the file icon yields its width, and the chapter indicator truncates inside a bounded share of the row instead of disappearing. The selection panel becomes a bottom card on phones: collapsed rows for short content, a capped scrollable body for the note editor and overflow actions, a drag handle for pull-down-to- dismiss, and safe-area padding; the desktop popover is unchanged. Refs #916 Co-authored-by: XZH <cto@xzh.ai>
67 lines
1.9 KiB
TypeScript
67 lines
1.9 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;
|
|
/**
|
|
* Shown below the `md` breakpoint only — a control the converged mobile
|
|
* header moved into this menu (#916). Desktop keeps it where it was, so
|
|
* the menu does not offer it twice.
|
|
*/
|
|
mobileOnly?: 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;
|
|
}
|