Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

adaptive-workspace-context.ts

73 lines2.9 KB

1import { createContext, use, type ReactNode } from "react";
2import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
3import {
4 deriveFileInspectorPaneLayout,
5 deriveLayout,
6 deriveWorkspacePaneLayout,
7 type FileInspectorPaneLayout,
8 type Layout,
9 type WorkspaceAuxiliaryPaneRole,
10 type WorkspacePaneLayout,
11} from "../../lib/layout";
12​
13interface AdaptiveWorkspaceContextValue {
14 readonly layout: Layout;
15 readonly panes: WorkspacePaneLayout;
16 readonly fileInspector: FileInspectorPaneLayout;
17 readonly primarySidebarSearchQuery: string;
18 readonly startNewTask: () => void;
19 readonly deferThreadSelectionUntil: (operation: Promise<unknown>) => void;
20 readonly selectThread: (thread: EnvironmentThreadShell) => void;
21 readonly selectThreadRoute: (params: ReactNavigation.RootParamList["Thread"]) => void;
22 readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void;
23 readonly registerWorkspaceInspector: (render: () => ReactNode) => () => void;
24 readonly setPrimarySidebarSearchQuery: (query: string) => void;
25 readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void;
26 readonly toggleAuxiliaryPane: () => void;
27 readonly togglePrimarySidebar: () => void;
28 readonly setPrimarySidebarVisible: (visible: boolean) => void;
29 readonly setAuxiliaryPaneWidth: (width: number) => void;
30 /**
31 * Android split view while the thread composer has the soft keyboard: the
32 * sidebar and rail step aside and the thread header drops to one line.
33 */
34 readonly composerKeyboardActive: boolean;
35 /** The thread composer reports its focus so the layout can make room for typing. */
36 readonly setComposerEditing: (editing: boolean) => void;
38​
39const compactLayout = deriveLayout({ width: 0, height: 0 });
40const compactPanes = deriveWorkspacePaneLayout({
41 layout: compactLayout,
42 viewportWidth: 0,
43 primarySidebarPreferredVisible: true,
44 auxiliaryPanePreferredVisible: true,
45});
46const compactFileInspector = deriveFileInspectorPaneLayout({
47 layout: compactLayout,
48 viewportWidth: 0,
49});
50export const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextValue>({
51 layout: compactLayout,
52 panes: compactPanes,
53 fileInspector: compactFileInspector,
54 primarySidebarSearchQuery: "",
55 startNewTask: () => undefined,
56 deferThreadSelectionUntil: () => undefined,
57 selectThread: () => undefined,
58 selectThreadRoute: () => undefined,
59 activateAuxiliaryPaneRole: () => () => undefined,
60 registerWorkspaceInspector: () => () => undefined,
61 setPrimarySidebarSearchQuery: () => undefined,
62 showAuxiliaryPane: () => undefined,
63 toggleAuxiliaryPane: () => undefined,
64 togglePrimarySidebar: () => undefined,
65 setPrimarySidebarVisible: () => undefined,
66 setAuxiliaryPaneWidth: () => undefined,
67 composerKeyboardActive: false,
68 setComposerEditing: () => undefined,
69});
70​
71export function useAdaptiveWorkspaceLayout(): AdaptiveWorkspaceContextValue {
72 return use(AdaptiveWorkspaceContext);