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