GeezerVison is showing github.com — fix(mobile): snooze menu times advance with the clock (#26043) · pingdotgg/t3code@a56ecda
File treeExpand file treeCollapse file tree Open diff view settings apps/mobile/src/features/threads
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/thread-list-v2-items.tsx +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,7 @@ import { | 26 | 26 | resolveThreadWorkingStartedAt, | 27 | 27 | } from "@t3tools/client-runtime/state/models"; | 28 | 28 | 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"; | 30 | 30 | import type { MenuAction } from "@react-native-menu/menu"; | 31 | 31 | import { memo, useCallback, useMemo, useState, type ComponentProps } from "react"; | 32 | 32 | import { Pressable, useWindowDimensions, View } from "react-native"; | @@ -63,6 +63,7 @@ import { | 63 | 63 | THREAD_LIST_V2_SETTLED_PAGE_COUNT, | 64 | 64 | resolveThreadListV2SnoozeGateExpiryMs, | 65 | 65 | resolveThreadListV2SnoozeMenuSelection, | | 66 | + resolveThreadListV2SnoozePresets, | 66 | 67 | threadHasUnseenCompletion, | 67 | 68 | resolveThreadListV2Status, | 68 | 69 | resolveThreadListV2ProviderDrivers, | @@ -756,12 +757,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { | 756 | 757 | snoozable: canSnooze(thread, { now: snoozeGateNow }), | 757 | 758 | snoozed: snoozedRow, | 758 | 759 | }); | 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 | + }); | 765 | 764 | const snoozePresetActions = useMemo<MenuAction[]>( | 766 | 765 | () => [ | 767 | 766 | ...snoozePresets.map((preset) => ({ | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/threadListV2.test.ts +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,6 +35,7 @@ import { | 35 | 35 | buildThreadListV2ListItems, | 36 | 36 | getThreadListV2OrderedSection, | 37 | 37 | resolveThreadListV2SnoozeMenuSelection, | | 38 | + resolveThreadListV2SnoozePresets, | 38 | 39 | resolveThreadListV2Status, | 39 | 40 | resolveThreadListV2WokeAt, | 40 | 41 | sortThreadsForListV2, | @@ -76,6 +77,22 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => { | 76 | 77 | }); | 77 | 78 | }); | 78 | 79 |
| | 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 | + | 79 | 96 | describe("resolveThreadListV2Status", () => { | 80 | 97 | it("presents decoded thread waits as Waiting while preserving requests and older servers", () => { | 81 | 98 | const raw = makeRawThreadShell({ | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/threadListV2.ts +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,6 +72,18 @@ export type ThreadListV2Status = | 72 | 72 | | "ready"; | 73 | 73 | export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze"; | 74 | 74 |
| | 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 | + | 75 | 87 | export function resolveThreadListV2SnoozeMenuSelection(input: { | 76 | 88 | readonly event: string; | 77 | 89 | readonly displayedPresets: ReadonlyArray<SnoozePreset>; | |
|