@devries-cameron20 / t3code-1 / commits / edf5a24b56
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(mobile): subagent timers share the visible second clock (#25854)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 03:59 UTC edf5a24b568371b27f23cc5fff92b4a225df3276
3 files changed +40 -67
apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
+2 -7
@@ -11,7 +11,6 @@ import { StackActions, useNavigation, type StaticScreenProps } from "@react-navi
11 import * as DateTime from "effect/DateTime";
12 import { Atom } from "effect/reactivity";
13 import * as Haptics from "expo-haptics";
14 -import { useEffect, useState } from "react";
14 import { Platform, Pressable, ScrollView, View } from "react-native";
15 import { ScreenStack } from "react-native-screens";
16 import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -22,6 +21,7 @@ import { environmentThreadDetails } from "../../state/threads";
21 import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
22 import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
23 import { SubagentRow } from "./SubagentRow";
24 +import { useVisibleSecondClock } from "./use-visible-second-clock";
25 import { ScreenContent } from "../../components/ui/ScreenContent";
26 import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
27
@@ -195,13 +195,8 @@ function useSubagentElapsed(
195 subagent: Pick<OrchestrationV2Subagent, "status" | "startedAt" | "completedAt">,
196 tickSeconds: boolean,
197 ): string | null {
198 - const [nowMs, setNowMs] = useState(() => Date.now());
198 const running = isOrchestrationV2WorkActive(subagent.status);
200 - useEffect(() => {
201 - if (!tickSeconds || !running) return;
202 - const intervalId = setInterval(() => setNowMs(Date.now()), 1_000);
203 - return () => clearInterval(intervalId);
204 - }, [running, tickSeconds]);
199 + const nowMs = useVisibleSecondClock(tickSeconds && running);
200 const elapsedMs = deriveSubagentElapsedMs(
201 {
202 status: subagent.status,
apps/mobile/src/features/threads/thread-subagent-group.tsx
+4 -17
@@ -1,5 +1,5 @@
1 import { useAtomValue } from "@effect/atom-react";
2 -import { StackActions, useIsFocused, useNavigation } from "@react-navigation/native";
2 +import { StackActions, useNavigation } from "@react-navigation/native";
3 import { scopeThreadRef } from "@t3tools/client-runtime/environment";
4 import { summarizeSubagentStatuses } from "@t3tools/client-runtime/state/subagent-display";
5 import { isActiveSubagentStatus } from "@t3tools/client-runtime/state/subagentRuntime";
@@ -8,8 +8,7 @@ import type {
8 OrchestrationV2Subagent,
9 OrchestrationV2TurnItem,
10 } from "@t3tools/contracts";
11 -import { useEffect, useState } from "react";
12 -import { AppState, Pressable, View, type ColorValue } from "react-native";
11 +import { Pressable, View, type ColorValue } from "react-native";
12
13 import { AppText as Text } from "../../components/ui/AppText";
14 import { SymbolView } from "../../components/ui/AppSymbol";
@@ -20,6 +19,7 @@ import { serverEnvironment } from "../../state/server";
19 import { environmentThreadDetails } from "../../state/threads";
20 import { subagentCardElapsed } from "./subagent-card-presentation";
21 import { SubagentRow } from "./SubagentRow";
22 +import { useVisibleSecondClock } from "./use-visible-second-clock";
23 import { WorkLogBlock } from "./work-log-layout";
24
25 import { useOpenThreadInspector } from "./thread-inspector-navigation";
@@ -28,21 +28,8 @@ type SubagentItem = Extract<OrchestrationV2TurnItem, { type: "subagent" }>;
28 type AgentTiming = Pick<OrchestrationV2Subagent, "status" | "startedAt" | "completedAt">;
29
30 function SubagentElapsed({ agents }: { readonly agents: ReadonlyArray<AgentTiming> }) {
31 - const focused = useIsFocused();
31 const live = agents.some((agent) => isActiveSubagentStatus(agent.status));
33 - const [nowMs, setNowMs] = useState(() => Date.now());
34 - const [appActive, setAppActive] = useState(() => AppState.currentState === "active");
35 - useEffect(() => {
36 - const subscription = AppState.addEventListener("change", (state) =>
37 - setAppActive(state === "active"),
38 - );
39 - return () => subscription.remove();
40 - }, []);
41 - useEffect(() => {
42 - if (!live || !focused || !appActive) return;
43 - const intervalId = setInterval(() => setNowMs(Date.now()), 1_000);
44 - return () => clearInterval(intervalId);
45 - }, [appActive, focused, live]);
32 + const nowMs = useVisibleSecondClock(live);
33 const elapsed = subagentCardElapsed(agents, nowMs);
34 return elapsed ? (
35 <Text className="shrink-0 text-xs tabular-nums text-foreground-muted">{elapsed}</Text>
apps/mobile/src/features/threads/useFileChipShare.ts
+34 -43
@@ -2,7 +2,7 @@ import * as Dialog from "../../components/ui/Dialog";
2 import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets";
3 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
4 import * as Option from "effect/Option";
5 -import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
5 +import { useEffect, useRef } from "react";
6
7 import { downloadAndShareAttachment } from "../../lib/attachmentDownload";
8 import { assetEnvironment } from "../../state/assets";
@@ -21,49 +21,40 @@ export function useFileChipShare(
21 refresh: true,
22 reportFailure: false,
23 });
24 - const connectionRef = useRef(httpBaseUrl);
25 - useLayoutEffect(() => {
26 - connectionRef.current = httpBaseUrl;
27 - }, [httpBaseUrl]);
24 const requestRef = useRef<AbortController | null>(null);
25 useEffect(() => () => requestRef.current?.abort(), []);
26
31 - const share = useCallback(
32 - (target: FileChipTarget) => {
33 - const source = fileChipShareSource(target, threadId);
34 - if (!source || requestRef.current) return;
35 - const request = new AbortController();
36 - requestRef.current = request;
37 - const httpBaseUrl = connectionRef.current;
38 - void (async () => {
39 - if (httpBaseUrl === null) throw new Error("Reconnect to the environment and try again.");
40 - const result = await createUrl({ environmentId, input: { resource: source.resource } });
41 - if (request.signal.aborted) return;
42 - const url =
43 - result._tag === "Success" ? resolveAssetUrl(httpBaseUrl, result.value.relativeUrl) : null;
44 - if (url === null) throw new Error("The file could not be loaded. Reconnect and try again.");
45 - await downloadAndShareAttachment({
46 - url,
47 - attachment: source,
48 - signal: request.signal,
49 - sourceIdentifier,
50 - });
51 - })()
52 - .catch((error: unknown) => {
53 - if (!request.signal.aborted) {
54 - Dialog.alert(
55 - "Could not share file",
56 - error instanceof Error ? error.message : "Try again.",
57 - );
58 - }
59 - })
60 - .finally(() => {
61 - if (requestRef.current === request) {
62 - requestRef.current = null;
63 - }
64 - });
65 - },
66 - [createUrl, environmentId, sourceIdentifier, threadId],
67 - );
68 - return share;
27 + return (target: FileChipTarget) => {
28 + const source = fileChipShareSource(target, threadId);
29 + if (!source || requestRef.current) return;
30 + const request = new AbortController();
31 + requestRef.current = request;
32 + void (async () => {
33 + if (httpBaseUrl === null) throw new Error("Reconnect to the environment and try again.");
34 + const result = await createUrl({ environmentId, input: { resource: source.resource } });
35 + if (request.signal.aborted) return;
36 + const url =
37 + result._tag === "Success" ? resolveAssetUrl(httpBaseUrl, result.value.relativeUrl) : null;
38 + if (url === null) throw new Error("The file could not be loaded. Reconnect and try again.");
39 + await downloadAndShareAttachment({
40 + url,
41 + attachment: source,
42 + signal: request.signal,
43 + sourceIdentifier,
44 + });
45 + })()
46 + .catch((error: unknown) => {
47 + if (!request.signal.aborted) {
48 + Dialog.alert(
49 + "Could not share file",
50 + error instanceof Error ? error.message : "Try again.",
51 + );
52 + }
53 + })
54 + .finally(() => {
55 + if (requestRef.current === request) {
56 + requestRef.current = null;
57 + }
58 + });
59 + };
60 }