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

v5-workspace-context.tsx

38 lines1.6 KB

1import { createContext, type ReactNode } from "react";
2​
3export const NativeWorkspaceModeContext = createContext(false);
4/**
5 * Each workspace tab slot renders the same routes, so header options a screen sets are kept per
6 * slot (by route key) instead of on the shared route: a slot's header then never shows options
7 * another slot set, and switching tabs has nothing left to update.
8 */
9export interface WorkspaceSlotOptions {
10 readonly byRoute: ReadonlyMap<string, object>;
11 readonly set: (routeKey: string, options: object) => void;
13export const WorkspaceSlotOptionsContext = createContext<WorkspaceSlotOptions | null>(null);
14​
15/** A route's options with whatever its screens set within this slot on top. */
16export function slotScreenOptions<Options extends object>(
17 slot: WorkspaceSlotOptions | null,
18 routeKey: string | undefined,
19 options: Options,
20): Options {
21 const own = routeKey === undefined ? undefined : slot?.byRoute.get(routeKey);
22 return own ? { ...options, ...own } : options;
24​
25/** Retained tabs must not update another tab's navigation options. */
26export const NativeWorkspaceTabActivityContext = createContext<{
27 readonly active: boolean;
28 readonly isActive: () => boolean;
29} | null>(null);
30export const NativePrimaryColumnContext = createContext<{
31 readonly presented: boolean;
32 readonly selectedThreadKey: string | null;
33 readonly selectedPullRequestKey: string | null;
34} | null>(null);
35export const NativeWorkspaceInspectorContext = createContext<{
36 readonly render: (() => ReactNode) | undefined;
37 readonly visible: boolean;
38}>({ render: undefined, visible: false });