MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / pickShellWorkspace

Function pickShellWorkspace

web/src/lib/stores/shellWorkspace.ts:12–23  ·  view source on GitHub ↗
(
	workspaces: Workspace[] | null | undefined,
	last: LastWorkspace | null | undefined,
	tabs: WorkspaceTab[] | null | undefined
)

Source from the content-addressed store, hash-verified

10const same = (w: Workspace, ref: Ref) => !!ref && w.slug === ref.slug && w.owner_username === ref.owner_username;
11
12export function pickShellWorkspace(
13 workspaces: Workspace[] | null | undefined,
14 last: LastWorkspace | null | undefined,
15 tabs: WorkspaceTab[] | null | undefined
16): Workspace | undefined {
17 const list = workspaces ?? [];
18 return (
19 list.find((w) => same(w, last)) ??
20 (tabs ?? []).map((t) => list.find((w) => same(w, t))).find((w) => !!w) ??
21 list[0]
22 );
23}

Callers 1

Calls 2

findMethod · 0.80
sameFunction · 0.70

Tested by

no test coverage detected