Skip to content

Commit 9d3ffa0

Browse files
committed
fix(mobile): keep home brand visible during secondary retries
1 parent 07d38b8 commit 9d3ffa0

6 files changed

Lines changed: 96 additions & 5 deletions

File tree

‎apps/mobile/src/features/home/workspace-connection-status.test.ts‎

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState
99
hasConnections: true,
1010
hasLoadedShellSnapshot: true,
1111
hasPendingShellSnapshot: false,
12+
hasSyncingConnectedEnvironment: false,
1213
hasReadyEnvironment: true,
1314
hasConnectingEnvironment: false,
1415
connectingEnvironments: [],
@@ -25,6 +26,66 @@ describe("workspace connection status", () => {
2526
expect(workspaceConnectionStatusPresentation(workspaceState())).toBeNull();
2627
});
2728

29+
it.each([
30+
["connecting", null],
31+
["reconnecting", null],
32+
["connecting", "Could not reach sleeping laptop"],
33+
["reconnecting", "Could not reach sleeping laptop"],
34+
["error", "Could not reach sleeping laptop"],
35+
] as const)(
36+
"keeps the brand while a secondary environment is %s (%s)",
37+
(connectionState, connectionError) => {
38+
const state = workspaceState({
39+
hasConnectingEnvironment: connectionState !== "error",
40+
hasPendingShellSnapshot: true,
41+
connectionError,
42+
connectingEnvironments:
43+
connectionState === "error"
44+
? []
45+
: [
46+
{
47+
environmentId: "environment-2" as never,
48+
environmentLabel: "Sleeping laptop",
49+
displayUrl: "",
50+
isRelayManaged: false,
51+
isEnabled: true,
52+
connectionState,
53+
connectionError,
54+
connectionErrorTraceId: null,
55+
},
56+
],
57+
});
58+
59+
expect(workspaceConnectionStatusPresentation(state)).toBeNull();
60+
},
61+
);
62+
63+
it("shows connected shell catch-up even while a secondary environment is unreachable", () => {
64+
const state = workspaceState({
65+
hasSyncingConnectedEnvironment: true,
66+
hasPendingShellSnapshot: true,
67+
hasConnectingEnvironment: true,
68+
connectionError: "Could not reach sleeping laptop",
69+
connectingEnvironments: [
70+
{
71+
environmentId: "environment-2" as never,
72+
environmentLabel: "Sleeping laptop",
73+
displayUrl: "",
74+
isRelayManaged: false,
75+
isEnabled: true,
76+
connectionState: "reconnecting",
77+
connectionError: "Could not reach sleeping laptop",
78+
connectionErrorTraceId: null,
79+
},
80+
],
81+
});
82+
83+
expect(workspaceConnectionStatusPresentation(state)).toEqual({
84+
label: "Syncing threads...",
85+
showsProgress: true,
86+
});
87+
});
88+
2889
it("surfaces offline snapshots", () => {
2990
const state = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
3091

@@ -72,7 +133,10 @@ describe("workspace connection status", () => {
72133
});
73134

74135
it("shows shell catch-up while cached threads remain visible", () => {
75-
const state = workspaceState({ hasPendingShellSnapshot: true });
136+
const state = workspaceState({
137+
hasPendingShellSnapshot: true,
138+
hasSyncingConnectedEnvironment: true,
139+
});
76140

77141
expect(workspaceConnectionStatusPresentation(state)).toEqual({
78142
label: "Syncing threads...",
@@ -84,6 +148,7 @@ describe("workspace connection status", () => {
84148
const state = workspaceState({
85149
hasLoadedShellSnapshot: false,
86150
hasPendingShellSnapshot: true,
151+
hasSyncingConnectedEnvironment: true,
87152
});
88153

89154
expect(workspaceConnectionStatusPresentation(state)).toEqual({

‎apps/mobile/src/features/home/workspace-connection-status.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export interface WorkspaceConnectionStatusPresentation {
66
}
77

88
function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): boolean {
9+
if (state.networkStatus === "offline") return true;
10+
if (state.hasReadyEnvironment) return state.hasSyncingConnectedEnvironment;
911
return (
10-
state.networkStatus === "offline" ||
1112
state.connectionError !== null ||
1213
state.hasConnectingEnvironment ||
1314
state.hasPendingShellSnapshot ||
@@ -17,6 +18,9 @@ function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): boolean {
1718

1819
function workspaceConnectionStatusLabel(state: WorkspaceState): string {
1920
if (state.networkStatus === "offline") return "You are offline";
21+
if (state.hasReadyEnvironment && state.hasSyncingConnectedEnvironment) {
22+
return state.hasLoadedShellSnapshot ? "Syncing threads..." : "Loading threads...";
23+
}
2024
if (state.connectingEnvironments.length === 1) {
2125
return `Reconnecting to ${state.connectingEnvironments[0]!.environmentLabel}`;
2226
}
@@ -38,7 +42,7 @@ export function workspaceConnectionStatusPresentation(
3842
label: workspaceConnectionStatusLabel(state),
3943
showsProgress:
4044
state.networkStatus !== "offline" &&
41-
state.connectionError === null &&
45+
(state.hasReadyEnvironment || state.connectionError === null) &&
4246
(state.connectingEnvironments.length > 0 || state.hasPendingShellSnapshot),
4347
};
4448
}

‎apps/mobile/src/state/workspace-connection-atoms.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe("workspace connection subscriptions", () => {
6262
networkStatus: get(h.network),
6363
environments: [projectWorkspaceEnvironment(ID, get(h.source)!)],
6464
shellSummary: get(shell),
65+
hasSyncingConnectedEnvironment: false,
6566
}),
6667
);
6768
const initial = h.registry.get(h.stateAtom);

‎apps/mobile/src/state/workspace.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useAtomValue } from "@effect/atom-react";
22
import { useMemo } from "react";
3+
import { Atom } from "effect/reactivity";
34

4-
import { environmentShellSummaryAtom } from "./shell";
5+
import { environmentShell, environmentShellSummaryAtom } from "./shell";
56
import { projectWorkspaceState } from "./workspaceModel";
67
import { environmentCatalog } from "../connection/catalog";
78
import { environmentPresentations } from "./presentation";
@@ -13,6 +14,16 @@ export const workspaceConnections = createWorkspaceConnectionAtoms({
1314
presentationAtom: environmentPresentations.presentationAtom,
1415
});
1516

17+
// A disconnected environment's retries also leave its shell synchronizing.
18+
const hasSyncingConnectedEnvironmentAtom = Atom.make((get) =>
19+
get(workspaceConnections.environmentsAtom).some(
20+
(environment) =>
21+
environment.isEnabled &&
22+
environment.connectionState === "connected" &&
23+
get(environmentShell.stateValueAtom(environment.environmentId)).status === "synchronizing",
24+
),
25+
).pipe(Atom.withLabel("mobile:has-syncing-connected-environment"));
26+
1627
export function useWorkspaceEnvironments() {
1728
return useAtomValue(workspaceConnections.environmentsAtom);
1829
}
@@ -30,15 +41,17 @@ export function useWorkspaceState() {
3041
const networkStatus = useAtomValue(environmentCatalog.networkStatusValueAtom);
3142
const projectedEnvironments = useWorkspaceEnvironments();
3243
const shellSummary = useAtomValue(environmentShellSummaryAtom);
44+
const hasSyncingConnectedEnvironment = useAtomValue(hasSyncingConnectedEnvironmentAtom);
3345
const state = useMemo(
3446
() =>
3547
projectWorkspaceState({
3648
isReady,
3749
networkStatus,
3850
environments: projectedEnvironments,
3951
shellSummary,
52+
hasSyncingConnectedEnvironment,
4053
}),
41-
[isReady, networkStatus, projectedEnvironments, shellSummary],
54+
[isReady, networkStatus, projectedEnvironments, shellSummary, hasSyncingConnectedEnvironment],
4255
);
4356

4457
return {

‎apps/mobile/src/state/workspaceModel.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe("mobile workspace projection", () => {
7777
networkStatus: "offline",
7878
environments,
7979
shellSummary: EMPTY_SHELL_SUMMARY,
80+
hasSyncingConnectedEnvironment: false,
8081
});
8182

8283
expect(state.connectionState).toBe("offline");
@@ -94,12 +95,14 @@ describe("mobile workspace projection", () => {
9495
networkStatus: "online",
9596
environments,
9697
shellSummary: EMPTY_SHELL_SUMMARY,
98+
hasSyncingConnectedEnvironment: true,
9799
});
98100

99101
expect(state.connectingEnvironments).toHaveLength(1);
100102
expect(state.connectingEnvironments[0]?.connectionState).toBe("reconnecting");
101103
expect(state.hasConnectingEnvironment).toBe(true);
102104
expect(state.hasReadyEnvironment).toBe(true);
105+
expect(state.hasSyncingConnectedEnvironment).toBe(true);
103106
});
104107

105108
it("keeps retained snapshots visible while reconnecting without claiming readiness", () => {
@@ -109,10 +112,12 @@ describe("mobile workspace projection", () => {
109112
networkStatus: "online",
110113
environments,
111114
shellSummary: CACHED_SHELL_SUMMARY,
115+
hasSyncingConnectedEnvironment: false,
112116
});
113117

114118
expect(state.hasLoadedShellSnapshot).toBe(true);
115119
expect(state.hasPendingShellSnapshot).toBe(true);
120+
expect(state.hasSyncingConnectedEnvironment).toBe(false);
116121
expect(state.hasReadyEnvironment).toBe(false);
117122
expect(state.connectionState).toBe("reconnecting");
118123
});

‎apps/mobile/src/state/workspaceModel.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface WorkspaceConnectionState {
2525
export interface WorkspaceState extends WorkspaceConnectionState {
2626
readonly hasLoadedShellSnapshot: boolean;
2727
readonly hasPendingShellSnapshot: boolean;
28+
readonly hasSyncingConnectedEnvironment: boolean;
2829
readonly shellSnapshotError: string | null;
2930
}
3031

@@ -92,11 +93,13 @@ export function projectWorkspaceState(input: {
9293
readonly networkStatus: NetworkStatus;
9394
readonly environments: ReadonlyArray<WorkspaceEnvironment>;
9495
readonly shellSummary: EnvironmentShellSummary;
96+
readonly hasSyncingConnectedEnvironment: boolean;
9597
}): WorkspaceState {
9698
return {
9799
...projectWorkspaceConnectionState(input),
98100
hasLoadedShellSnapshot: input.shellSummary.hasSnapshot,
99101
hasPendingShellSnapshot: input.shellSummary.hasSynchronizingShell,
102+
hasSyncingConnectedEnvironment: input.hasSyncingConnectedEnvironment,
100103
shellSnapshotError: input.shellSummary.firstError,
101104
};
102105
}

0 commit comments

Comments
 (0)