fix(mobile): guard snooze/wake double-taps; read wake time to screen readers
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) <[email protected]>
This commit is contained in:
1 parent
cf2b02f8e9
commit
71bf16596d
2 files changed
+60
-32
No files matched your search
@@ -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<string>());
|
||||
|
||||
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],
|
||||
);
|
||||
|
||||
@@ -484,7 +484,17 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
) : (
|
||||
<Pressable
|
||||
accessibilityHint={swipeAccessibilityHint}
|
||||
accessibilityLabel={thread.title}
|
||||
// The wake countdown is the row's whole story visually; a screen
|
||||
// reader must hear it too, not just the Wake hint.
|
||||
accessibilityLabel={
|
||||
snoozedRow && props.snoozeWakeLabelText !== undefined
|
||||
? // The label can read "now" for the sliver between the wake
|
||||
// passing and the next re-partition removing the row.
|
||||
props.snoozeWakeLabelText === "now"
|
||||
? `${thread.title}, snoozed, wakes now`
|
||||
: `${thread.title}, snoozed, wakes in ${props.snoozeWakeLabelText}`
|
||||
: thread.title
|
||||
}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
className={sidebarPane ? undefined : "bg-screen"}
|
||||
|
||||
Reference in new issue
Block a user