Skip to content

Commit 31eb9b7

Browse files
fix(mobile): rows on an unreachable host say why they can't be changed
A thread row on a host the app can't reach dropped its swipe actions and long-press menu without any visible reason. The row now shows the host's connection issue (Offline, Reconnecting…, Can't connect, Unsupported, Not connected), and long-press opens a menu that explains why actions are unavailable and keeps Copy thread ID. Expired credentials and view-only pairings get their own explanation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0712398 commit 31eb9b7

4 files changed

Lines changed: 210 additions & 13 deletions

File tree

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ import {
2525
formatWorkingDurationLabel,
2626
resolveThreadWorkingStartedAt,
2727
} from "@t3tools/client-runtime/state/models";
28-
import { AuthOrchestrationOperateScope, type EnvironmentMachineKind } from "@t3tools/contracts";
28+
import {
29+
AuthOrchestrationOperateScope,
30+
type EnvironmentId,
31+
type EnvironmentMachineKind,
32+
} from "@t3tools/contracts";
2933
import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
34+
import { useAtomValue } from "@effect/atom-react";
3035
import type { MenuAction } from "@react-native-menu/menu";
36+
import { Atom } from "effect/reactivity";
3137
import { memo, useCallback, useEffect, useMemo, useState, type ComponentProps } from "react";
3238
import { Pressable, useWindowDimensions, View } from "react-native";
3339
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
@@ -42,7 +48,8 @@ import { ProviderIcon, ProviderInstanceIcon } from "../../components/ProviderIco
4248
import { cn } from "../../lib/cn";
4349
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
4450
import { useUniwindTheme } from "../../lib/useUniwindTheme";
45-
import { useEnvironmentScope } from "../../state/session";
51+
import { environmentPresentations } from "../../state/presentation";
52+
import { useEnvironmentScopeAccess } from "../../state/session";
4653
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
4754
import {
4855
resolveThreadPrBadgeAction,
@@ -60,6 +67,9 @@ import {
6067
resolveThreadListV2Status,
6168
resolveThreadListV2ProviderDrivers,
6269
resolveThreadListV2SwipeActions,
70+
resolveThreadListV2ConnectionIssue,
71+
resolveThreadListV2LockedReason,
72+
THREAD_LIST_V2_CONNECTION_ISSUE_LABEL,
6373
type ThreadListV2Status,
6474
} from "./threadListV2";
6575
import { QueuedMessageIcon } from "./queued-message-icon";
@@ -68,6 +78,15 @@ import { ThreadSearchMatchExcerpt } from "./thread-search-match";
6878
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
6979
import { pullRequestStatus } from "../pull-requests/pullRequestStatus";
7080

81+
// A string, so rows re-render only when the issue changes, not on every catalog update.
82+
const environmentConnectionIssueAtom = Atom.family((environmentId: EnvironmentId) =>
83+
Atom.make((get) =>
84+
resolveThreadListV2ConnectionIssue(
85+
get(environmentPresentations.presentationAtom(environmentId))?.connection ?? null,
86+
),
87+
),
88+
);
89+
7190
const TITLE_FAVICON_SIZE = 15;
7291
// Centers the favicon on the first line of the text-base title.
7392
const TITLE_FAVICON_OFFSET = 4;
@@ -681,7 +700,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
681700

682701
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
683702
const handleRename = useCallback(() => onRenameThread(thread), [onRenameThread, thread]);
684-
const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope);
703+
const operateAccess = useEnvironmentScopeAccess(
704+
thread.environmentId,
705+
AuthOrchestrationOperateScope,
706+
);
707+
const canOperateThread = operateAccess === "granted";
708+
const connectionIssue = useAtomValue(environmentConnectionIssueAtom(thread.environmentId));
709+
const connectionLabel =
710+
connectionIssue === null ? null : THREAD_LIST_V2_CONNECTION_ISSUE_LABEL[connectionIssue];
685711
const handleRegenerateTitle = useCallback(
686712
() => onRegenerateThreadTitle(thread),
687713
[onRegenerateThreadTitle, thread],
@@ -995,8 +1021,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
9951021
: null,
9961022
[handleMenuAction, snoozePresetActions, swipeActions.secondary, thread.title],
9971023
);
1024+
const lockedMenuTitle =
1025+
operateAccess === "granted"
1026+
? ""
1027+
: resolveThreadListV2LockedReason({
1028+
access: operateAccess,
1029+
connectionIssue,
1030+
environmentLabel: props.environmentLabel ?? null,
1031+
});
9981032
const swipeAccessibilityHint = !canOperateThread
999-
? "Opens the thread"
1033+
? `Opens the thread. ${lockedMenuTitle}`
10001034
: secondaryAction === null
10011035
? `Opens the thread. Swipe left to ${primaryAction.label.toLowerCase()}.`
10021036
: `Opens the thread. Swipe left for ${primaryAction.label.toLowerCase()} and snooze actions.`;
@@ -1121,7 +1155,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11211155
</View>
11221156
) : null}
11231157
<View className="mt-1 flex-row items-center gap-2" style={{ paddingLeft: titleTextInset }}>
1124-
{(status === "failed" || status === "limited") && thread.runtime?.lastError ? (
1158+
{(status === "failed" || status === "limited") &&
1159+
thread.runtime?.lastError &&
1160+
// A host that dropped explains the row better than its last run's error.
1161+
connectionLabel === null ? (
11251162
<Text
11261163
className={cn(
11271164
"flex-1 text-xs",
@@ -1135,9 +1172,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11351172
>
11361173
{thread.runtime.lastError}
11371174
</Text>
1138-
) : props.environmentLabel ? (
1175+
) : props.environmentLabel || connectionLabel ? (
11391176
<View className="min-w-0 flex-1 flex-row items-center gap-1">
1140-
{props.environmentMachine ? (
1177+
{props.environmentLabel && props.environmentMachine ? (
11411178
<EnvironmentMachineSymbol
11421179
kind={props.environmentMachine}
11431180
size={11}
@@ -1158,6 +1195,19 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11581195
numberOfLines={1}
11591196
>
11601197
{props.environmentLabel}
1198+
{props.environmentLabel && connectionLabel ? " · " : null}
1199+
{connectionLabel ? (
1200+
<Text
1201+
className={cn(
1202+
"text-xs",
1203+
selected
1204+
? selectedThreadRowColors.mutedForegroundClassName
1205+
: "text-warning-foreground",
1206+
)}
1207+
>
1208+
{connectionLabel}
1209+
</Text>
1210+
) : null}
11611211
</Text>
11621212
</View>
11631213
) : (
@@ -1328,6 +1378,19 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
13281378
/>
13291379
) : null}
13301380
</View>
1381+
{connectionLabel ? (
1382+
<Text
1383+
className={cn(
1384+
"text-xs",
1385+
selected
1386+
? selectedThreadRowColors.mutedForegroundClassName
1387+
: "text-warning-foreground",
1388+
)}
1389+
numberOfLines={1}
1390+
>
1391+
{connectionLabel}
1392+
</Text>
1393+
) : null}
13311394
{props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
13321395
<Text
13331396
className={cn(
@@ -1349,7 +1412,18 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
13491412
);
13501413

13511414
if (!canOperateThread)
1352-
return <View style={rowAppearance.swipeContainerStyle}>{rowContent(() => {})}</View>;
1415+
return (
1416+
<View style={rowAppearance.swipeContainerStyle}>
1417+
<Menu
1418+
title={lockedMenuTitle}
1419+
actions={[{ id: "copy-thread-id", title: "Copy thread ID", image: "doc.on.doc" }]}
1420+
onPressAction={handleMenuAction}
1421+
shouldOpenOnLongPress
1422+
>
1423+
{rowContent(() => {})}
1424+
</Menu>
1425+
</View>
1426+
);
13531427

13541428
return (
13551429
<View collapsable={false}>

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
buildThreadListV2Items,
3535
buildThreadListV2ListItems,
3636
getThreadListV2OrderedSection,
37+
resolveThreadListV2ConnectionIssue,
38+
resolveThreadListV2LockedReason,
3739
resolveThreadListV2SnoozeMenuSelection,
3840
resolveThreadListV2Status,
3941
resolveThreadListV2WokeAt,
@@ -76,6 +78,45 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {
7678
});
7779
});
7880

81+
describe("thread rows on hosts they cannot change", () => {
82+
it("names the connection issue and stays quiet while connected or on a first attempt", () => {
83+
expect(resolveThreadListV2ConnectionIssue({ phase: "connected", error: null })).toBeNull();
84+
expect(resolveThreadListV2ConnectionIssue({ phase: "connecting", error: null })).toBeNull();
85+
expect(resolveThreadListV2ConnectionIssue(null)).toBeNull();
86+
expect(resolveThreadListV2ConnectionIssue({ phase: "offline", error: null })).toBe("offline");
87+
expect(resolveThreadListV2ConnectionIssue({ phase: "reconnecting", error: null })).toBe(
88+
"reconnecting",
89+
);
90+
expect(resolveThreadListV2ConnectionIssue({ phase: "reconnecting", error: "timeout" })).toBe(
91+
"unreachable",
92+
);
93+
expect(resolveThreadListV2ConnectionIssue({ phase: "error", error: null })).toBe("unreachable");
94+
});
95+
96+
it("explains a missing grant, expired credentials, and connection issues differently", () => {
97+
const reason = (
98+
access: "denied" | "signed-out" | "unknown",
99+
connectionIssue: Parameters<typeof resolveThreadListV2LockedReason>[0]["connectionIssue"],
100+
) => resolveThreadListV2LockedReason({ access, connectionIssue, environmentLabel: "lxso2" });
101+
102+
expect(reason("denied", null)).toBe(
103+
"This device can view threads on lxso2 but not change them.",
104+
);
105+
expect(reason("signed-out", null)).toBe(
106+
"This device is no longer signed in to lxso2. Pair again to change threads.",
107+
);
108+
expect(reason("unknown", "unsupported")).toBe(
109+
"lxso2 and this app need compatible versions before threads can be changed.",
110+
);
111+
expect(reason("unknown", "unreachable")).toBe(
112+
"Thread actions are unavailable until lxso2 reconnects.",
113+
);
114+
expect(reason("unknown", null)).toBe(
115+
"Thread actions are unavailable until lxso2 confirms this device's access.",
116+
);
117+
});
118+
});
119+
79120
describe("resolveThreadListV2Status", () => {
80121
it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {
81122
const raw = makeRawThreadShell({

‎apps/mobile/src/features/threads/threadListV2.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
threadWokeAt,
99
} from "@t3tools/client-runtime/state/thread-settled";
1010
import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled";
11+
import type { EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection";
1112
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
1213
import { resolveThreadProviderStack } from "@t3tools/client-runtime/state/models";
1314
import {
@@ -120,6 +121,68 @@ export function resolveThreadListV2SwipeActions(input: {
120121
};
121122
}
122123

124+
export type ThreadListV2ConnectionIssue =
125+
| "offline"
126+
| "reconnecting"
127+
| "unreachable"
128+
| "unsupported"
129+
| "disconnected";
130+
131+
export const THREAD_LIST_V2_CONNECTION_ISSUE_LABEL: Record<ThreadListV2ConnectionIssue, string> = {
132+
offline: "Offline",
133+
reconnecting: "Reconnecting…",
134+
unreachable: "Can't connect",
135+
unsupported: "Unsupported",
136+
disconnected: "Not connected",
137+
};
138+
139+
// Cached shells keep listing a host's threads after it drops; the row says so
140+
// instead of silently refusing swipes and menus.
141+
export function resolveThreadListV2ConnectionIssue(
142+
connection: Pick<EnvironmentConnectionPresentation, "phase" | "error"> | null,
143+
): ThreadListV2ConnectionIssue | null {
144+
switch (connection?.phase) {
145+
case undefined:
146+
case "connected":
147+
// Every host passes through its first attempt at launch; labelling it would
148+
// flash on each row. A failed attempt moves on to "reconnecting".
149+
case "connecting":
150+
return null;
151+
case "reconnecting":
152+
return connection.error === null ? "reconnecting" : "unreachable";
153+
case "error":
154+
return "unreachable";
155+
case "unsupported":
156+
return "unsupported";
157+
case "offline":
158+
return "offline";
159+
case "available":
160+
return "disconnected";
161+
}
162+
}
163+
164+
export function resolveThreadListV2LockedReason(input: {
165+
readonly access: "denied" | "signed-out" | "unknown";
166+
readonly connectionIssue: ThreadListV2ConnectionIssue | null;
167+
readonly environmentLabel: string | null;
168+
}): string {
169+
const environment = input.environmentLabel ?? "this environment";
170+
if (input.access === "denied") {
171+
return `This device can view threads on ${environment} but not change them.`;
172+
}
173+
if (input.access === "signed-out") {
174+
return `This device is no longer signed in to ${environment}. Pair again to change threads.`;
175+
}
176+
if (input.connectionIssue === "unsupported") {
177+
return `${environment} and this app need compatible versions before threads can be changed.`;
178+
}
179+
if (input.connectionIssue !== null) {
180+
return `Thread actions are unavailable until ${environment} reconnects.`;
181+
}
182+
// Covers both a host still connecting and a session lookup that failed on a live socket.
183+
return `Thread actions are unavailable until ${environment} confirms this device's access.`;
184+
}
185+
123186
export function resolveThreadListV2SnoozeGateExpiryMs(
124187
thread: Pick<
125188
EnvironmentThreadShell,

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,43 @@ export const environmentSession = createEnvironmentSessionAtoms(connectionAtomRu
1717

1818
const EMPTY_SESSION_STATE_ATOM = Atom.make(AsyncResult.initial<AuthSessionState>());
1919

20+
export type EnvironmentScopeAccess = "granted" | "denied" | "signed-out" | "unknown";
21+
22+
function sessionScopeAccess(
23+
result: AsyncResult.AsyncResult<AuthSessionState, unknown>,
24+
scope: AuthEnvironmentScope,
25+
): EnvironmentScopeAccess {
26+
const session = Option.getOrNull(AsyncResult.value(result));
27+
if (result._tag === "Failure" || session === null) return "unknown";
28+
if (!session.authenticated) return "signed-out";
29+
return sessionGrantsScope(session, scope) ? "granted" : "denied";
30+
}
31+
2032
function sessionHasScope(
2133
result: AsyncResult.AsyncResult<AuthSessionState, unknown>,
2234
scope: AuthEnvironmentScope,
2335
): boolean {
24-
const session = Option.getOrNull(AsyncResult.value(result));
25-
return result._tag !== "Failure" && session !== null && sessionGrantsScope(session, scope);
36+
return sessionScopeAccess(result, scope) === "granted";
2637
}
2738

28-
export function useEnvironmentScope(
39+
/** Separates a grant the session lacks from expired credentials and a session that never loaded. */
40+
export function useEnvironmentScopeAccess(
2941
environmentId: EnvironmentId | null,
3042
scope: AuthEnvironmentScope,
31-
): boolean {
43+
): EnvironmentScopeAccess {
3244
const result = useAtomValue(
3345
environmentId === null
3446
? EMPTY_SESSION_STATE_ATOM
3547
: environmentSession.sessionStateAtom(environmentId),
3648
);
37-
return sessionHasScope(result, scope);
49+
return sessionScopeAccess(result, scope);
50+
}
51+
52+
export function useEnvironmentScope(
53+
environmentId: EnvironmentId | null,
54+
scope: AuthEnvironmentScope,
55+
): boolean {
56+
return useEnvironmentScopeAccess(environmentId, scope) === "granted";
3857
}
3958

4059
export function useEnvironmentsWithScope(

0 commit comments

Comments
 (0)