Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/mobile/src/features/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ function deriveEmptyState(props: {
};
}

if (!catalogState.hasEnabledEnvironment) {
return {
title: "Environments switched off",
detail: "Turn an environment on in Settings → Environments to load projects.",
loading: false,
};
}

if (
(catalogState.connectionState === "available" ||
catalogState.connectionState === "offline" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState
return {
isLoadingConnections: false,
hasConnections: true,
hasEnabledEnvironment: true,
hasLoadedShellSnapshot: true,
hasPendingShellSnapshot: false,
hasSyncingConnectedEnvironment: false,
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/features/threads/NewTaskRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ function deriveProjectEmptyState(catalogState: WorkspaceState): {
};
}

if (!catalogState.hasEnabledEnvironment) {
return {
title: "Environments switched off",
detail: "Turn an environment on in Settings → Environments before creating a task.",
loading: false,
};
}

if (
(catalogState.connectionState === "available" ||
catalogState.connectionState === "offline" ||
Expand Down
43 changes: 43 additions & 0 deletions apps/mobile/src/state/workspaceModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,47 @@ describe("mobile workspace projection", () => {
expect(state.hasReadyEnvironment).toBe(false);
expect(state.connectionState).toBe("reconnecting");
});

it("keeps the detail with the environment whose state names the title", () => {
const blocked = environment("unsupported");
const environments = [
projectWorkspaceEnvironment(EnvironmentId.make("environment-failed"), environment("error")),
projectWorkspaceEnvironment(ENVIRONMENT_ID, {
...blocked,
connection: { ...blocked.connection, error: "Update T3 Code on the host to connect." },
}),
];
const state = projectWorkspaceState({
isReady: true,
networkStatus: "online",
environments,
shellSummary: EMPTY_SHELL_SUMMARY,
hasSyncingConnectedEnvironment: false,
});

expect(state.connectionState).toBe("unsupported");
expect(state.connectionError).toBe("Update T3 Code on the host to connect.");
});

it("does not report environments the user switched off", () => {
const failed = environment("error");
const environments = [
projectWorkspaceEnvironment(ENVIRONMENT_ID, {
...failed,
entry: { ...failed.entry, enabled: false },
}),
];
const state = projectWorkspaceState({
isReady: true,
networkStatus: "online",
environments,
shellSummary: EMPTY_SHELL_SUMMARY,
hasSyncingConnectedEnvironment: false,
});

expect(state.hasConnections).toBe(true);
expect(state.hasEnabledEnvironment).toBe(false);
expect(state.connectionState).toBe("available");
expect(state.connectionError).toBeNull();
});
});
20 changes: 16 additions & 4 deletions apps/mobile/src/state/workspaceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type { EnvironmentConnectionSummary as WorkspaceEnvironment } from "@t3to
export interface WorkspaceConnectionState {
readonly isLoadingConnections: boolean;
readonly hasConnections: boolean;
readonly hasEnabledEnvironment: boolean;
readonly hasReadyEnvironment: boolean;
readonly hasConnectingEnvironment: boolean;
readonly connectingEnvironments: ReadonlyArray<WorkspaceEnvironment>;
Expand Down Expand Up @@ -71,18 +72,29 @@ export function projectWorkspaceConnectionState(input: {
environment.connectionState === "reconnecting",
);

const connectionState = overallConnectionState(activeEnvironments, input.networkStatus);
const withError = activeEnvironments.filter(
(environment) => environment.connectionError !== null,
);
// The detail must explain the state the title names, so prefer an environment
// in that state. The status banner still surfaces any other failure.
const connectionError =
(
withError.find((environment) => environment.connectionState === connectionState) ??
withError[0]
)?.connectionError ?? null;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

return {
isLoadingConnections: !input.isReady,
hasConnections: input.environments.length > 0,
hasEnabledEnvironment: activeEnvironments.length > 0,
hasReadyEnvironment:
input.networkStatus !== "offline" &&
activeEnvironments.some((environment) => environment.connectionState === "connected"),
hasConnectingEnvironment: connectingEnvironments.length > 0,
connectingEnvironments,
connectionState: overallConnectionState(activeEnvironments, input.networkStatus),
connectionError:
activeEnvironments.find((environment) => environment.connectionError !== null)
?.connectionError ?? null,
connectionState,
connectionError,
networkStatus: input.networkStatus,
};
}
Expand Down
Loading