Skip to content

Commit a56ecda

Browse files
fix(mobile): snooze menu times advance with the clock (#26043)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 76d5ec7 commit a56ecda

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
resolveThreadWorkingStartedAt,
2727
} from "@t3tools/client-runtime/state/models";
2828
import { AuthOrchestrationOperateScope, type EnvironmentMachineKind } from "@t3tools/contracts";
29-
import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
29+
import { canSnooze } from "@t3tools/client-runtime/state/thread-settled";
3030
import type { MenuAction } from "@react-native-menu/menu";
3131
import { memo, useCallback, useMemo, useState, type ComponentProps } from "react";
3232
import { Pressable, useWindowDimensions, View } from "react-native";
@@ -63,6 +63,7 @@ import {
6363
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
6464
resolveThreadListV2SnoozeGateExpiryMs,
6565
resolveThreadListV2SnoozeMenuSelection,
66+
resolveThreadListV2SnoozePresets,
6667
threadHasUnseenCompletion,
6768
resolveThreadListV2Status,
6869
resolveThreadListV2ProviderDrivers,
@@ -756,12 +757,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
756757
snoozable: canSnooze(thread, { now: snoozeGateNow }),
757758
snoozed: snoozedRow,
758759
});
759-
const snoozePresets = useMemo(
760-
// oxlint-disable-next-line react/purity -- The memo recomputes on the snoozePresetMinute tick, so preset times refresh every minute.
761-
() => (swipeActions.secondary === "snooze" ? resolveSnoozePresets(new Date()) : ([] as const)),
762-
// oxlint-disable-next-line react/memo-dependencies -- The minute tick refreshes relative snooze times while the row remains mounted.
763-
[props.snoozePresetMinute, swipeActions.secondary],
764-
);
760+
const snoozePresets = resolveThreadListV2SnoozePresets({
761+
secondary: swipeActions.secondary,
762+
now: props.snoozePresetMinute || snoozeGateNow,
763+
});
765764
const snoozePresetActions = useMemo<MenuAction[]>(
766765
() => [
767766
...snoozePresets.map((preset) => ({

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
buildThreadListV2ListItems,
3636
getThreadListV2OrderedSection,
3737
resolveThreadListV2SnoozeMenuSelection,
38+
resolveThreadListV2SnoozePresets,
3839
resolveThreadListV2Status,
3940
resolveThreadListV2WokeAt,
4041
sortThreadsForListV2,
@@ -76,6 +77,22 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {
7677
});
7778
});
7879

80+
describe("resolveThreadListV2SnoozePresets", () => {
81+
it("reads preset times from the list minute, not the clock at first render", () => {
82+
using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
83+
vi.useFakeTimers({ now: new Date(2026, 4, 8, 10) });
84+
const laterMinute = new Date(2026, 4, 8, 19, 15).toISOString();
85+
86+
const presets = resolveThreadListV2SnoozePresets({ secondary: "snooze", now: laterMinute });
87+
88+
expect(presets.find((preset) => preset.id === "hour")?.snoozedUntil).toBe(
89+
new Date(2026, 4, 8, 20, 15).toISOString(),
90+
);
91+
// The evening preset is gone by 19:15; a reading from 10:00 would still offer it.
92+
expect(presets.map((preset) => preset.id)).not.toContain("evening");
93+
});
94+
});
95+
7996
describe("resolveThreadListV2Status", () => {
8097
it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {
8198
const raw = makeRawThreadShell({

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ export type ThreadListV2Status =
7272
| "ready";
7373
export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze";
7474

75+
/**
76+
* Presets for a row's snooze menu, read at the list's minute instead of the
77+
* clock: the compiler keys a row's memo on its inputs, so a clock read inside
78+
* it would keep the times from the row's first render.
79+
*/
80+
export function resolveThreadListV2SnoozePresets(input: {
81+
readonly secondary: "snooze" | null;
82+
readonly now: string;
83+
}): ReadonlyArray<SnoozePreset> {
84+
return input.secondary === "snooze" ? resolveSnoozePresets(new Date(input.now)) : [];
85+
}
86+
7587
export function resolveThreadListV2SnoozeMenuSelection(input: {
7688
readonly event: string;
7789
readonly displayedPresets: ReadonlyArray<SnoozePreset>;

0 commit comments

Comments
 (0)