Skip to content

Commit 209ad89

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-25891
2 parents 8d9ec2f + 79f6cd3 commit 209ad89

20 files changed

Lines changed: 279 additions & 272 deletions

‎apps/mobile/src/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {
8585
} from "./lib/rootNavigation";
8686
import { pruneNewTaskFlowStates } from "./features/threads/new-task-flow-state";
8787
import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen";
88+
import { installAppUpdateChecks } from "./features/updates/app-updates";
8889

8990
import "../global.css";
9091

@@ -176,6 +177,7 @@ const appServiceDisposers = [
176177
startIncomingShareInbox(),
177178
installAgentNotificationNavigation(linkToAppPath),
178179
installAppShortcuts(linkToAppPath),
180+
installAppUpdateChecks(),
179181
];
180182
disposeOnFoundationReplace(typeof module === "undefined" ? undefined : module.hot, () => {
181183
for (const dispose of appServiceDisposers) dispose();

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
2222
import { useDeviceType, useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
2323
import { WorkspaceEmptyDetail } from "../layout/WorkspaceEmptyDetail";
2424
import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
25-
import { checkForAppUpdateOnLaunch, startAppUpdateForegroundRecheck } from "../updates/app-updates";
2625
import { AndroidHomeFabLayout } from "./AndroidHomeFab";
2726
import { HomeScreen } from "./HomeScreen";
2827
import { HomeHeader } from "./HomeHeader";
@@ -95,11 +94,6 @@ export function HomeRouteScreen() {
9594
[selectThreadRoute],
9695
);
9796

98-
useEffect(() => {
99-
void checkForAppUpdateOnLaunch();
100-
startAppUpdateForegroundRecheck();
101-
}, []);
102-
10397
const {
10498
archiveThread,
10599
confirmDeleteThread,

‎apps/mobile/src/features/home/WorkspaceConnectionTitle.tsx‎

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NativeStackNavigationOptions } from "@react-navigation/native-stack";
2-
import { createContext, use, useEffect, useMemo, useState, type ReactNode } from "react";
2+
import { createContext, use, useEffect, useState, type ReactNode } from "react";
33
import { Animated, Platform, Pressable, View } from "react-native";
44

55
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
@@ -11,6 +11,7 @@ import {
1111
CompactBrandTitle,
1212
getCompactBrandHeaderOptions,
1313
} from "../../components/CompactBrandTitle";
14+
import { useDeadlinePassed } from "../../lib/clock";
1415
import { useWorkspaceState } from "../../state/workspace";
1516
import {
1617
workspaceConnectionStatusPresentation,
@@ -37,29 +38,24 @@ export function WorkspaceConnectionStatusProvider(props: { readonly children: Re
3738
const { state } = useWorkspaceState();
3839
const presentation = workspaceConnectionStatusPresentation(state);
3940
const hasStatus = presentation !== null;
40-
const [phase, setPhase] = useState<"waiting" | "fading" | "shown">("waiting");
41-
42-
useEffect(() => {
43-
if (!hasStatus) return;
44-
const timers = [
45-
setTimeout(() => setPhase("fading"), STATUS_SHOW_DELAY_MS),
46-
setTimeout(() => setPhase("shown"), STATUS_SHOW_DELAY_MS + FADE_IN_MS),
47-
];
48-
return () => {
49-
for (const timer of timers) clearTimeout(timer);
50-
setPhase("waiting");
51-
};
52-
}, [hasStatus]);
41+
// When the current status run began; a gap in the status restarts the delay.
42+
const [statusSince, setStatusSince] = useState(() => (hasStatus ? Date.now() : null));
43+
if (hasStatus !== (statusSince !== null)) {
44+
// oxlint-disable-next-line react/purity -- Reads the clock only in the render-phase adjustment that runs when the status appears.
45+
setStatusSince(hasStatus ? Date.now() : null);
46+
}
47+
const since = hasStatus ? statusSince : null;
48+
const fadeStarted = useDeadlinePassed(since === null ? null : since + STATUS_SHOW_DELAY_MS);
49+
const fadeEnded = useDeadlinePassed(
50+
since === null ? null : since + STATUS_SHOW_DELAY_MS + FADE_IN_MS,
51+
);
5352

5453
const label = presentation?.label;
5554
const showsProgress = presentation?.showsProgress ?? false;
56-
const status = useMemo(
57-
() =>
58-
label === undefined || phase === "waiting"
59-
? null
60-
: { label, showsProgress, fadeIn: phase === "fading" },
61-
[label, showsProgress, phase],
62-
);
55+
const status =
56+
label === undefined || since === null || !fadeStarted
57+
? null
58+
: { label, showsProgress, fadeIn: !fadeEnded };
6359
return <ConnectionStatusContext value={status}>{props.children}</ConnectionStatusContext>;
6460
}
6561

@@ -72,7 +68,6 @@ function StatusFadeIn(props: {
7268
}) {
7369
const { animate } = props;
7470
const [opacity] = useState(() => new Animated.Value(0));
75-
7671
useEffect(() => {
7772
if (!animate) return;
7873
const animation = Animated.timing(opacity, {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { EnvironmentId } from "@t3tools/contracts";
2+
import { act, useLayoutEffect } from "react";
3+
import { createRoot } from "react-dom/client";
4+
import { expect, it, vi } from "vite-plus/test";
5+
6+
const harness = vi.hoisted(() => ({ saved: [] as unknown[] }));
7+
8+
vi.mock("../../state/preferences", () => ({ updateMobilePreferencesAtom: {} }));
9+
vi.mock("@effect/atom-react", async (importOriginal) => ({
10+
...(await importOriginal<typeof import("@effect/atom-react")>()),
11+
useAtomSet: () => (value: unknown) => harness.saved.push(value),
12+
}));
13+
14+
import { HomeListOptionsProvider, useHomeListOptions } from "./home-list-options";
15+
16+
const ENVIRONMENT = "env-1" as EnvironmentId;
17+
const AVAILABLE = new Set([ENVIRONMENT]);
18+
19+
it("saves the scope from every update made in one event", async () => {
20+
harness.saved = [];
21+
let controls: ReturnType<typeof useHomeListOptions> | undefined;
22+
function Probe() {
23+
const result = useHomeListOptions(AVAILABLE);
24+
useLayoutEffect(() => {
25+
controls = result;
26+
});
27+
return null;
28+
}
29+
30+
const root = createRoot(document.createElement("div"));
31+
await act(async () =>
32+
root.render(
33+
<HomeListOptionsProvider projectGroupingMode="repository">
34+
<Probe />
35+
</HomeListOptionsProvider>,
36+
),
37+
);
38+
act(() => {
39+
controls!.setSelectedEnvironmentId(ENVIRONMENT);
40+
controls!.setSelectedProjectKey("env-1:project-1");
41+
});
42+
43+
expect(harness.saved.at(-1)).toEqual({
44+
threadListFilters: { environmentId: ENVIRONMENT, projectKey: "env-1:project-1" },
45+
});
46+
expect(controls!.options.selectedEnvironmentId).toBe(ENVIRONMENT);
47+
expect(controls!.options.selectedProjectKey).toBe("env-1:project-1");
48+
act(() => root.unmount());
49+
});

‎apps/mobile/src/features/home/home-list-options.ts‎

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
import type { EnvironmentId, SidebarProjectGroupingMode } from "@t3tools/contracts";
22
import { DEFAULT_SIDEBAR_PROJECT_SORT_ORDER } from "@t3tools/contracts";
3-
import { useAtomSet } from "@effect/atom-react";
4-
import {
5-
createContext,
6-
createElement,
7-
useContext,
8-
useEffect,
9-
useRef,
10-
useState,
11-
type PropsWithChildren,
12-
type Dispatch,
13-
type SetStateAction,
14-
} from "react";
3+
import { RegistryContext, useAtomSet, useAtomValue } from "@effect/atom-react";
4+
import { Atom } from "effect/reactivity";
5+
import { createContext, createElement, useContext, useState, type PropsWithChildren } from "react";
156

167
import type { ThreadListFilters } from "../../persistence/mobile-preferences";
178
import { updateMobilePreferencesAtom } from "../../state/preferences";
@@ -40,7 +31,7 @@ function defaultHomeListOptions(filters?: ThreadListFilters): HomeListOptions {
4031

4132
interface HomeListOptionsContextValue {
4233
readonly options: HomeListOptions;
43-
readonly setOptions: Dispatch<SetStateAction<HomeListOptions>>;
34+
readonly updateOptions: (patch: Partial<HomeListOptions>) => void;
4435
readonly projectGroupingMode: SidebarProjectGroupingMode;
4536
}
4637

@@ -54,28 +45,39 @@ export function HomeListOptionsProvider({
5445
readonly projectGroupingMode: SidebarProjectGroupingMode;
5546
readonly savedFilters?: ThreadListFilters | undefined;
5647
}>) {
57-
const [options, setOptions] = useState(() => defaultHomeListOptions(savedFilters));
48+
const registry = useContext(RegistryContext);
49+
const [optionsAtom] = useState(() => Atom.make(defaultHomeListOptions(savedFilters)));
50+
const options = useAtomValue(optionsAtom);
5851
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
59-
const saved = useRef(savedFilters);
60-
const { selectedEnvironmentId: environmentId, selectedProjectKey: projectKey } = options;
61-
useEffect(() => {
52+
// Only the scope persists; the sort order is per session. Updates read the
53+
// registry, so several in one event each build on the last and save it.
54+
const updateOptions = (patch: Partial<HomeListOptions>) => {
55+
const current = registry.get(optionsAtom);
56+
const next = { ...current, ...patch };
57+
registry.set(optionsAtom, next);
6258
if (
63-
(saved.current?.environmentId ?? null) === environmentId &&
64-
(saved.current?.projectKey ?? null) === projectKey
65-
)
66-
return;
67-
saved.current = { environmentId, projectKey };
68-
savePreferences({ threadListFilters: saved.current });
69-
}, [environmentId, projectKey, savePreferences]);
70-
const value = { options, setOptions, projectGroupingMode };
59+
next.selectedEnvironmentId !== current.selectedEnvironmentId ||
60+
next.selectedProjectKey !== current.selectedProjectKey
61+
) {
62+
savePreferences({
63+
threadListFilters: {
64+
environmentId: next.selectedEnvironmentId,
65+
projectKey: next.selectedProjectKey,
66+
},
67+
});
68+
}
69+
};
70+
const value = { options, updateOptions, projectGroupingMode };
7171
return createElement(HomeListOptionsContext, { value }, children);
7272
}
7373

7474
export function useHomeListOptions(availableEnvironmentIds: ReadonlySet<EnvironmentId>) {
7575
const shared = useContext(HomeListOptionsContext);
7676
const [localOptions, setLocalOptions] = useState<HomeListOptions>(defaultHomeListOptions);
7777
const options = shared?.options ?? localOptions;
78-
const setOptions = shared?.setOptions ?? setLocalOptions;
78+
const updateOptions =
79+
shared?.updateOptions ??
80+
((patch: Partial<HomeListOptions>) => setLocalOptions((current) => ({ ...current, ...patch })));
7981
const selectedEnvironmentId =
8082
options.selectedEnvironmentId !== null &&
8183
availableEnvironmentIds.has(options.selectedEnvironmentId)
@@ -91,13 +93,13 @@ export function useHomeListOptions(availableEnvironmentIds: ReadonlySet<Environm
9193
};
9294

9395
const setSelectedEnvironmentId = (value: EnvironmentId | null) => {
94-
setOptions((current) => ({ ...current, selectedEnvironmentId: value }));
96+
updateOptions({ selectedEnvironmentId: value });
9597
};
9698
const setSelectedProjectKey = (value: string | null) => {
97-
setOptions((current) => ({ ...current, selectedProjectKey: value }));
99+
updateOptions({ selectedProjectKey: value });
98100
};
99101
const setProjectSortOrder = (value: HomeProjectSortOrder) => {
100-
setOptions((current) => ({ ...current, projectSortOrder: value }));
102+
updateOptions({ projectSortOrder: value });
101103
};
102104
return {
103105
options: resolvedOptions,

‎apps/mobile/src/features/threads/ThreadAgentsSheet.tsx‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { StackActions, useNavigation, type StaticScreenProps } from "@react-navi
1111
import * as DateTime from "effect/DateTime";
1212
import { Atom } from "effect/reactivity";
1313
import * as Haptics from "expo-haptics";
14-
import { useEffect, useState } from "react";
1514
import { Platform, Pressable, ScrollView, View } from "react-native";
1615
import { ScreenStack } from "react-native-screens";
1716
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -22,6 +21,7 @@ import { environmentThreadDetails } from "../../state/threads";
2221
import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
2322
import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
2423
import { SubagentRow } from "./SubagentRow";
24+
import { useVisibleSecondClock } from "./use-visible-second-clock";
2525
import { ScreenContent } from "../../components/ui/ScreenContent";
2626
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
2727

@@ -195,13 +195,8 @@ function useSubagentElapsed(
195195
subagent: Pick<OrchestrationV2Subagent, "status" | "startedAt" | "completedAt">,
196196
tickSeconds: boolean,
197197
): string | null {
198-
const [nowMs, setNowMs] = useState(() => Date.now());
199198
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);
205200
const elapsedMs = deriveSubagentElapsedMs(
206201
{
207202
status: subagent.status,

‎apps/mobile/src/features/threads/thread-subagent-group.tsx‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import { StackActions, useIsFocused, useNavigation } from "@react-navigation/native";
2+
import { StackActions, useNavigation } from "@react-navigation/native";
33
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
44
import { summarizeSubagentStatuses } from "@t3tools/client-runtime/state/subagent-display";
55
import { isActiveSubagentStatus } from "@t3tools/client-runtime/state/subagentRuntime";
@@ -8,8 +8,7 @@ import type {
88
OrchestrationV2Subagent,
99
OrchestrationV2TurnItem,
1010
} 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";
1312

1413
import { AppText as Text } from "../../components/ui/AppText";
1514
import { SymbolView } from "../../components/ui/AppSymbol";
@@ -20,6 +19,7 @@ import { serverEnvironment } from "../../state/server";
2019
import { environmentThreadDetails } from "../../state/threads";
2120
import { subagentCardElapsed } from "./subagent-card-presentation";
2221
import { SubagentRow } from "./SubagentRow";
22+
import { useVisibleSecondClock } from "./use-visible-second-clock";
2323
import { WorkLogBlock } from "./work-log-layout";
2424

2525
import { useOpenThreadInspector } from "./thread-inspector-navigation";
@@ -28,21 +28,8 @@ type SubagentItem = Extract<OrchestrationV2TurnItem, { type: "subagent" }>;
2828
type AgentTiming = Pick<OrchestrationV2Subagent, "status" | "startedAt" | "completedAt">;
2929

3030
function SubagentElapsed({ agents }: { readonly agents: ReadonlyArray<AgentTiming> }) {
31-
const focused = useIsFocused();
3231
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);
4633
const elapsed = subagentCardElapsed(agents, nowMs);
4734
return elapsed ? (
4835
<Text className="shrink-0 text-xs tabular-nums text-foreground-muted">{elapsed}</Text>

0 commit comments

Comments
 (0)