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

v5-workspace-context.tsx

40 lines1.6 KB

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