diff --git a/src/components/EmailListPanel.tsx b/src/components/EmailListPanel.tsx index 0808031..0733e4e 100644 --- a/src/components/EmailListPanel.tsx +++ b/src/components/EmailListPanel.tsx @@ -446,9 +446,22 @@ export default function EmailListPanel({ }; }, [autoSyncCheck, autoSyncIntervalMs, inboxId, router, startTransition]); + function applySelection(next: Set) { + setSelectedIds(next); + setSelectionMode(next.size > 0); + } + + function toggleSelection(emailIds: string[]) { + const next = new Set(selectedIds); + const allChecked = emailIds.every((id) => next.has(id)); + emailIds.forEach((id) => + allChecked ? next.delete(id) : next.add(id) + ); + applySelection(next); + } + function clearSelection() { - setSelectedIds(new Set()); - setSelectionMode(false); + applySelection(new Set()); } function startLongPress(e: React.PointerEvent, emailIds: string[]) { @@ -457,8 +470,7 @@ export default function EmailListPanel({ longPressTimer.current = setTimeout(() => { longPressActive.current = true; if ("vibrate" in navigator) navigator.vibrate(50); - setSelectionMode(true); - setSelectedIds(new Set(emailIds)); + applySelection(new Set(emailIds)); }, 500); } @@ -1052,7 +1064,11 @@ export default function EmailListPanel({