TypeScript
fix(mobile): snooze menu times advance with the clock (#26043)
Julius Marmingea56ecdafa7c9
diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsxindex 031b2bd5290..8935877d28b 100644--- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx+++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx@@ -26,7 +26,7 @@ import {resolveThreadWorkingStartedAt,} from "@t3tools/client-runtime/state/models";import { AuthOrchestrationOperateScope, type EnvironmentMachineKind } from "@t3tools/contracts";-import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";+import { canSnooze } from "@t3tools/client-runtime/state/thread-settled";import type { MenuAction } from "@react-native-menu/menu";import { memo, useCallback, useMemo, useState, type ComponentProps } from "react";import { Pressable, useWindowDimensions, View } from "react-native";@@ -63,6 +63,7 @@ import {THREAD_LIST_V2_SETTLED_PAGE_COUNT,resolveThreadListV2SnoozeGateExpiryMs,resolveThreadListV2SnoozeMenuSelection,+ resolveThreadListV2SnoozePresets,threadHasUnseenCompletion,resolveThreadListV2Status,resolveThreadListV2ProviderDrivers,@@ -756,12 +757,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {snoozable: canSnooze(thread, { now: snoozeGateNow }),snoozed: snoozedRow,});- const snoozePresets = useMemo(- // oxlint-disable-next-line react/purity -- The memo recomputes on the snoozePresetMinute tick, so preset times refresh every minute.- () => (swipeActions.secondary === "snooze" ? resolveSnoozePresets(new Date()) : ([] as const)),- // oxlint-disable-next-line react/memo-dependencies -- The minute tick refreshes relative snooze times while the row remains mounted.- [props.snoozePresetMinute, swipeActions.secondary],- );+ const snoozePresets = resolveThreadListV2SnoozePresets({+ secondary: swipeActions.secondary,+ now: props.snoozePresetMinute || snoozeGateNow,+ });const snoozePresetActions = useMemo<MenuAction[]>(() => [...snoozePresets.map((preset) => ({diff --git a/apps/mobile/src/features/threads/threadListV2.test.ts b/apps/mobile/src/features/threads/threadListV2.test.tsindex 18e8a2cf3b8..18ae87e431b 100644--- a/apps/mobile/src/features/threads/threadListV2.test.ts+++ b/apps/mobile/src/features/threads/threadListV2.test.ts@@ -35,6 +35,7 @@ import {buildThreadListV2ListItems,getThreadListV2OrderedSection,resolveThreadListV2SnoozeMenuSelection,+ resolveThreadListV2SnoozePresets,resolveThreadListV2Status,resolveThreadListV2WokeAt,sortThreadsForListV2,@@ -76,6 +77,22 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {});});+describe("resolveThreadListV2SnoozePresets", () => {+ it("reads preset times from the list minute, not the clock at first render", () => {+ using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };+ vi.useFakeTimers({ now: new Date(2026, 4, 8, 10) });+ const laterMinute = new Date(2026, 4, 8, 19, 15).toISOString();++ const presets = resolveThreadListV2SnoozePresets({ secondary: "snooze", now: laterMinute });++ expect(presets.find((preset) => preset.id === "hour")?.snoozedUntil).toBe(+ new Date(2026, 4, 8, 20, 15).toISOString(),+ );+ // The evening preset is gone by 19:15; a reading from 10:00 would still offer it.+ expect(presets.map((preset) => preset.id)).not.toContain("evening");+ });+});+describe("resolveThreadListV2Status", () => {it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {const raw = makeRawThreadShell({diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.tsindex 9adc18e7174..e2f826bae26 100644--- a/apps/mobile/src/features/threads/threadListV2.ts+++ b/apps/mobile/src/features/threads/threadListV2.ts@@ -72,6 +72,18 @@ export type ThreadListV2Status =| "ready";export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze";+/**+ * Presets for a row's snooze menu, read at the list's minute instead of the+ * clock: the compiler keys a row's memo on its inputs, so a clock read inside+ * it would keep the times from the row's first render.+ */+export function resolveThreadListV2SnoozePresets(input: {+ readonly secondary: "snooze" | null;+ readonly now: string;+}): ReadonlyArray<SnoozePreset> {+ return input.secondary === "snooze" ? resolveSnoozePresets(new Date(input.now)) : [];+}+export function resolveThreadListV2SnoozeMenuSelection(input: {readonly event: string;readonly displayedPresets: ReadonlyArray<SnoozePreset>;