Open History to see the last commit
1import type { WorkspaceTab } from "../workspace/workspace-tabs-state";
2import { createContext, use, type ReactNode } from "react";
3import type {
4 WorkspaceDetail,
5 WorkspaceDetailSheet,
6} from "../workspace/workspace-detail-selection";
7import {
8 deriveFileInspectorPaneLayout,
9 deriveLayout,
10 deriveWorkspacePaneLayout,
11 type FileInspectorPaneLayout,
12 type Layout,
13 type WorkspaceAuxiliaryPaneRole,
14 type WorkspacePaneLayout,
15} from "../../lib/layout";
16
17interface AdaptiveWorkspaceContextValue {
18 readonly layout: Layout;
19 readonly panes: WorkspacePaneLayout;
20 readonly fileInspector: FileInspectorPaneLayout;
21 readonly primarySidebarSearchQuery: string;
22 readonly startNewTask: () => void;
23 /** Use `useSelectWorkspaceDetail`, which also works outside the layout. */
24 readonly selectDetail?: (detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => void;
25 readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void;
26 readonly registerWorkspaceInspector: (render: () => ReactNode) => () => void;
27 readonly setPrimarySidebarSearchQuery: (query: string) => void;
28 readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void;
29 readonly toggleAuxiliaryPane: () => void;
30 readonly togglePrimarySidebar: () => void;
31 readonly setPrimarySidebarVisible: (visible: boolean) => void;
32 /** Opens a workspace tab with its list and, with columns, the page it last showed. */
33 readonly openWorkspaceTab: (
34 tab: WorkspaceTab | "settings",
35 options?: { readonly columns?: boolean },
36 ) => void;
37 readonly setAuxiliaryPaneWidth: (width: number) => void;
38 /**
39 * Android split view while the thread composer has the soft keyboard: the
40 * sidebar and rail step aside and the thread header drops to one line.
41 */
42 readonly composerKeyboardActive: boolean;
43 /**
44 * Whether the sidebar shows in each orientation, where it floats over the content in portrait
45 * (the unfolded Duo). The native split switches between them as a rotation starts.
46 */
47 readonly sidebarByOrientation: { readonly landscape: boolean; readonly portrait: boolean } | null;
48 /** The thread composer reports its focus so the layout can make room for typing. */
49 readonly setComposerEditing: (editing: boolean) => void;
50}
51
52const compactLayout = deriveLayout({ width: 0, height: 0 });
53const compactPanes = deriveWorkspacePaneLayout({
54 layout: compactLayout,
55 viewportWidth: 0,
56 primarySidebarPreferredVisible: true,
57 auxiliaryPanePreferredVisible: true,
58});
59const compactFileInspector = deriveFileInspectorPaneLayout({
60 layout: compactLayout,
61 viewportWidth: 0,
62});
63export const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextValue>({
64 layout: compactLayout,
65 panes: compactPanes,
66 fileInspector: compactFileInspector,
67 primarySidebarSearchQuery: "",
68 startNewTask: () => undefined,
69 activateAuxiliaryPaneRole: () => () => undefined,
70 registerWorkspaceInspector: () => () => undefined,
71 setPrimarySidebarSearchQuery: () => undefined,
72 showAuxiliaryPane: () => undefined,
73 toggleAuxiliaryPane: () => undefined,
74 togglePrimarySidebar: () => undefined,
75 setPrimarySidebarVisible: () => undefined,
76 openWorkspaceTab: () => undefined,
77 setAuxiliaryPaneWidth: () => undefined,
78 composerKeyboardActive: false,
79 sidebarByOrientation: null,
80 setComposerEditing: () => undefined,
81});
82
83export function useAdaptiveWorkspaceLayout(): AdaptiveWorkspaceContextValue {
84 return use(AdaptiveWorkspaceContext);
85}