1import { isWorkspaceCatalogPending, type WorkspaceState } from "../../state/workspaceModel";
2
3export interface HomeEmptyState {
4 readonly title: string;
5 readonly detail: string;
6 readonly loading: boolean;
7 readonly showsAddEnvironment: boolean;
8}
9
10export function deriveHomeEmptyState(
11 catalogState: WorkspaceState,
12 projectCount: number,
13): HomeEmptyState {
14 const emptyState = deriveEmptyState(catalogState, projectCount);
15 return {
16 ...emptyState,
17 showsAddEnvironment: !emptyState.loading && !catalogState.hasReadyEnvironment,
18 };
19}
20
21function deriveEmptyState(
22 catalogState: WorkspaceState,
23 projectCount: number,
24): Omit<HomeEmptyState, "showsAddEnvironment"> {
25 if (catalogState.isLoadingConnections) {
26 return {
27 title: "Loading environments",
28 detail: "Checking saved environments on this device.",
29 loading: true,
30 };
31 }
32
33 if (!catalogState.hasConnections) {
34 return {
35 title: "No environments connected",
36 detail: "Add an environment to load projects and start coding sessions.",
37 loading: false,
38 };
39 }
40
41 if (
42 (catalogState.connectionState === "available" ||
43 catalogState.connectionState === "offline" ||
44 catalogState.connectionState === "error" ||
45 catalogState.connectionState === "unsupported") &&
46 !catalogState.hasLoadedShellSnapshot
47 ) {
48 return {
49 title:
50 catalogState.connectionState === "unsupported"
51 ? "Client not supported"
52 : "Environment unavailable",
53 detail:
54 catalogState.connectionError ??
55 "The saved environment is offline. Check the URL or start the environment, then retry.",
56 loading: false,
57 };
58 }
59
60 if (isWorkspaceCatalogPending(catalogState)) {
61 return {
62 title: catalogState.hasReadyEnvironment ? "Loading threads" : "Connecting to environment",
63 detail: "Loading projects and threads from the saved environment.",
64 loading: true,
65 };
66 }
67
68 if (projectCount === 0 && catalogState.hasLoadedShellSnapshot) {
69 return {
70 title: "No projects found",
71 detail: "The connected environment did not report any projects.",
72 loading: false,
73 };
74 }
75
76 return {
77 title: "No threads yet",
78 detail: "Create a task to start a new coding runtime in one of your connected projects.",
79 loading: false,
80 };
81}