From 71bf16596d77f62808022eaed3a8cdb67bba562b Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Thu, 30 Jul 2026 21:41:10 -0700 Subject: [PATCH] fix(mobile): guard snooze/wake double-taps; read wake time to screen readers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two low-severity findings from a gpt-5.6-sol (Codex) review of the branch: - snoozeThread/unsnoozeThread lacked the per-thread in-flight guard the other lifecycle actions get from executeAction, so rapid taps queued duplicate commands and stacked one failure alert per tap. Both now share a keyed guard (one set: snooze and wake on the same thread are mutually exclusive too). - Snoozed rows exposed only the thread title to VoiceOver/TalkBack; the wake countdown — the row's whole story visually — was invisible. The accessible label now reads "…, snoozed, wakes in 2h". Co-Authored-By: Claude Opus 5 (1M context) --- .../src/features/home/useThreadListActions.ts | 80 ++++++++++++------- .../features/threads/thread-list-v2-items.tsx | 12 ++- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts index 64dbbf81fc..bebf0cc480 100644 --- a/apps/mobile/src/features/home/useThreadListActions.ts +++ b/apps/mobile/src/features/home/useThreadListActions.ts @@ -208,6 +208,10 @@ export function useThreadListActions(): { const executeAction = useThreadActionExecutor(); const snoozeMutation = useAtomCommand(threadEnvironment.snooze, { reportFailure: false }); const unsnoozeMutation = useAtomCommand(threadEnvironment.unsnooze, { reportFailure: false }); + // Same double-tap guard executeAction gives the other lifecycle actions: + // without it a rapid second Wake/Snooze tap queues a duplicate command and, + // on failure, stacks one alert per tap. + const snoozeInFlightKeys = useRef(new Set()); const archiveThread = useCallback( (thread: EnvironmentThreadShell) => { @@ -221,6 +225,8 @@ export function useThreadListActions(): { ); const snoozeThread = useCallback( async (thread: EnvironmentThreadShell) => { + const key = scopedThreadKey(thread.environmentId, thread.id); + if (snoozeInFlightKeys.current.has(key)) return false; if (!environmentSupportsSnooze(thread.environmentId)) { Alert.alert( "Could not snooze thread", @@ -240,25 +246,30 @@ export function useThreadListActions(): { return false; } + snoozeInFlightKeys.current.add(key); selectionHaptic(); - const result = await snoozeMutation({ - environmentId: thread.environmentId, - input: { - threadId: thread.id, - snoozedUntil: new Date(Date.now() + SWIPE_SNOOZE_DURATION_MS).toISOString(), - }, - }); - if (result._tag === "Failure") { - const error = Cause.squash(result.cause); - Alert.alert( - "Could not snooze thread", - error instanceof Error && error.message.trim().length > 0 - ? error.message - : "The thread could not be snoozed.", - ); - return false; + try { + const result = await snoozeMutation({ + environmentId: thread.environmentId, + input: { + threadId: thread.id, + snoozedUntil: new Date(Date.now() + SWIPE_SNOOZE_DURATION_MS).toISOString(), + }, + }); + if (result._tag === "Failure") { + const error = Cause.squash(result.cause); + Alert.alert( + "Could not snooze thread", + error instanceof Error && error.message.trim().length > 0 + ? error.message + : "The thread could not be snoozed.", + ); + return false; + } + return true; + } finally { + snoozeInFlightKeys.current.delete(key); } - return true; }, [snoozeMutation], ); @@ -266,6 +277,8 @@ export function useThreadListActions(): { // the way OUT) — a thread the user can see on the shelf can always wake. const unsnoozeThread = useCallback( async (thread: EnvironmentThreadShell) => { + const key = scopedThreadKey(thread.environmentId, thread.id); + if (snoozeInFlightKeys.current.has(key)) return false; if (!environmentSupportsSnooze(thread.environmentId)) { Alert.alert( "Could not wake thread", @@ -274,22 +287,27 @@ export function useThreadListActions(): { return false; } + snoozeInFlightKeys.current.add(key); selectionHaptic(); - const result = await unsnoozeMutation({ - environmentId: thread.environmentId, - input: { threadId: thread.id, reason: "user" }, - }); - if (result._tag === "Failure") { - const error = Cause.squash(result.cause); - Alert.alert( - "Could not wake thread", - error instanceof Error && error.message.trim().length > 0 - ? error.message - : "The thread could not be woken.", - ); - return false; + try { + const result = await unsnoozeMutation({ + environmentId: thread.environmentId, + input: { threadId: thread.id, reason: "user" }, + }); + if (result._tag === "Failure") { + const error = Cause.squash(result.cause); + Alert.alert( + "Could not wake thread", + error instanceof Error && error.message.trim().length > 0 + ? error.message + : "The thread could not be woken.", + ); + return false; + } + return true; + } finally { + snoozeInFlightKeys.current.delete(key); } - return true; }, [unsnoozeMutation], ); diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsx index 459c09a689..10353f4fbc 100644 --- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx +++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx @@ -484,7 +484,17 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { ) : (