Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(email): swipe a row right to set a reminder on touch (#8239)

teoe000ab9d1160
diff --git a/apps/web/src/components/app/mobile/SwipableRow.test.tsx b/apps/web/src/components/app/mobile/SwipableRow.test.tsx
new file mode 100644
index 0000000000..7f3b9a57fa
--- /dev/null
+++ b/apps/web/src/components/app/mobile/SwipableRow.test.tsx
@@ -0,0 +1,101 @@
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import { SwipableRow, SwipableRowProvider } from './SwipableRow';
+
+vi.mock('@core/mobile/haptics', () => ({ hapticImpact: () => {} }));
+
+beforeEach(() => {
+ vi.useFakeTimers();
+ // jsdom has no layout; give rows a phone's width so a short drag does not
+ // count as dragging most of the way across.
+ vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(390);
+});
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+ vi.restoreAllMocks();
+});
+
+function touch(target: Element, type: string, x?: number) {
+ const event = new Event(type, { bubbles: true, cancelable: true });
+ const touches = x === undefined ? [] : [{ clientX: x, clientY: 20 }];
+ Object.defineProperty(event, 'touches', { value: touches });
+ target.dispatchEvent(event);
+}
+
+function swipe(from: number, to: number) {
+ const row = screen.getByText('Row');
+ touch(row, 'touchstart', from);
+ const step = (to - from) / 10;
+ for (let i = 1; i <= 10; i++) touch(row, 'touchmove', from + step * i);
+ touch(row, 'touchend');
+}
+
+function renderRow() {
+ const onSwipeLeft = vi.fn();
+ const onSwipeRight = vi.fn();
+ const canSwipeRight = vi.fn(() => true);
+ render(() => {
+ const [container, setContainer] = createSignal<HTMLElement>();
+ return (
+ <SwipableRowProvider
+ container={container}
+ onSwipeLeft={onSwipeLeft}
+ onSwipeRight={onSwipeRight}
+ canSwipeRight={canSwipeRight}
+ triggerBehavior={{ left: 'fly-out', right: 'spring-back' }}
+ >
+ <div ref={setContainer}>
+ <SwipableRow id="thread">
+ <div>Row</div>
+ </SwipableRow>
+ </div>
+ </SwipableRowProvider>
+ );
+ });
+ const content = () =>
+ screen.getByText('Row').closest<HTMLElement>('[data-swipe-content]')!;
+ return { onSwipeLeft, onSwipeRight, canSwipeRight, content };
+}
+
+it('runs a spring-back right swipe inside the gesture and keeps the row', () => {
+ const { onSwipeLeft, onSwipeRight, content } = renderRow();
+
+ swipe(80, 230);
+
+ // Synchronous, so an action that opens a sheet or keyboard still counts as
+ // a user gesture on iOS.
+ expect(onSwipeRight).toHaveBeenCalledWith('thread');
+ expect(onSwipeLeft).not.toHaveBeenCalled();
+ expect(content().style.transform).toBe('translateX(0px)');
+});
+
+it('still flies the row out for a left swipe', () => {
+ const { onSwipeLeft, onSwipeRight, content } = renderRow();
+
+ swipe(300, 150);
+
+ expect(content().style.transform).toBe('translateX(-100%)');
+ vi.advanceTimersByTime(100);
+ expect(onSwipeLeft).toHaveBeenCalledWith('thread');
+ expect(onSwipeRight).not.toHaveBeenCalled();
+});
+
+it('leaves right swipes from the left edge to back navigation', () => {
+ const { onSwipeRight } = renderRow();
+
+ swipe(10, 200);
+ vi.runAllTimers();
+
+ expect(onSwipeRight).not.toHaveBeenCalled();
+});
+
+it('asks whether a row can swipe once per gesture, not on every move', () => {
+ const { canSwipeRight, onSwipeRight } = renderRow();
+
+ swipe(80, 230);
+
+ expect(onSwipeRight).toHaveBeenCalledOnce();
+ expect(canSwipeRight).toHaveBeenCalledOnce();
+});
diff --git a/apps/web/src/components/app/mobile/SwipableRow.tsx b/apps/web/src/components/app/mobile/SwipableRow.tsx
index de67804ccf..64e37bc3c1 100644
--- a/apps/web/src/components/app/mobile/SwipableRow.tsx
+++ b/apps/web/src/components/app/mobile/SwipableRow.tsx
@@ -1,3 +1,4 @@
+import { SWIPE_EDGE_THRESHOLD } from '@components/app/split-layout/mobile/createMobileSplitMotion';
import { hapticImpact } from '@core/mobile/haptics';
import { cn } from '@ui';
import {
@@ -47,6 +48,8 @@ const isAtLeastPhase = (phase: RowPhase, minInclusive: RowPhase) =>
type SwipeDirection = 'left' | 'right' | null;
+type TriggerBehavior = 'fly-out' | 'spring-back';
+
type SwipableRowState = {
direction: SwipeDirection;
phase: RowPhase;
@@ -66,6 +69,11 @@ type SwipeTouchState = {
currentX: number;
currentY: number;
isSwipeGesture: boolean | null;
+ /** Started at the left edge, where a right swipe means "go back". */
+ fromLeftEdge: boolean;
+ /** Which swipes this row allows, decided once when the touch starts. */
+ allowRight: boolean;
+ allowLeft: boolean;
id: string | null;
elements: RowElements | undefined;
};
@@ -94,9 +102,12 @@ export function SwipableRowProvider(
* How a row animates once its swipe triggers. 'fly-out' (default)
* translates the row off-screen, for actions that remove the row from
* the list (e.g. mark done). 'spring-back' returns the row to rest, for
- * actions that keep it in place (e.g. reply to a message).
+ * actions that keep it in place (e.g. reply to a message). Give one per
+ * direction when the two swipes differ.
*/
- triggerBehavior?: 'fly-out' | 'spring-back';
+ triggerBehavior?:
+ | TriggerBehavior
+ | { left?: TriggerBehavior; right?: TriggerBehavior };
setCollapseEntity?: Setter<((id: string) => Promise<void>) | undefined>;
}>
) {
@@ -128,6 +139,9 @@ export function SwipableRowProvider(
currentX: 0,
currentY: 0,
isSwipeGesture: null,
+ fromLeftEdge: false,
+ allowRight: false,
+ allowLeft: false,
id: null,
elements: undefined,
};
@@ -158,6 +172,9 @@ export function SwipableRowProvider(
currentX: 0,
currentY: 0,
isSwipeGesture: null,
+ fromLeftEdge: false,
+ allowRight: false,
+ allowLeft: false,
id: null,
elements: undefined,
};
@@ -210,7 +227,11 @@ export function SwipableRowProvider(
// Cancel any pending animation frame
if (rafId) cancelAnimationFrame(rafId);
- if (props.triggerBehavior === 'spring-back') {
+ const behavior =
+ typeof props.triggerBehavior === 'object'
+ ? props.triggerBehavior[direction]
+ : props.triggerBehavior;
+ if (behavior === 'spring-back') {
// The row stays in the list: return the content to rest and fire the
// handler synchronously — still inside the touch gesture, so a
// handler that focuses an input can open the iOS keyboard.
@@ -244,6 +265,7 @@ export function SwipableRowProvider(
};
const canSwipeRight = (id: string) => {
+ if (touchState.fromLeftEdge) return false;
if (customRowSwipeHandlers.get(id)?.onSwipeRight !== undefined) return true;
if (!props.onSwipeRight) return false;
return props.canSwipeRight ? props.canSwipeRight(id) : true;
@@ -293,6 +315,10 @@ export function SwipableRowProvider(
const leftRevealEl = rowEl.querySelector('[data-left-reveal]');
const rightRevealEl = rowEl.querySelector('[data-right-reveal]');
+ const touch = e.touches[0];
+ // Touches at the left edge belong to the split's swipe-back gesture, so
+ // they never swipe a row right.
+ touchState.fromLeftEdge = touch.clientX < SWIPE_EDGE_THRESHOLD;
const allowRight = canSwipeRight(id);
const allowLeft = canSwipeLeft(id);
if (!allowRight && !allowLeft) return;
@@ -300,8 +326,6 @@ export function SwipableRowProvider(
const phase = stateById()[id]?.phase ?? 'idle';
if (phase === 'triggered' || phase === 'collapsing') return;
- const touch = e.touches[0];
-
// Clear any existing transition immediately on touch start.
contentEl.style.transition = '';
@@ -311,6 +335,9 @@ export function SwipableRowProvider(
currentX: touch.clientX,
currentY: touch.clientY,
isSwipeGesture: null,
+ fromLeftEdge: touchState.fromLeftEdge,
+ allowRight,
+ allowLeft,
id: id,
elements: {
rowEl,
@@ -346,8 +373,7 @@ export function SwipableRowProvider(
touchState.currentX = touch.clientX;
- const allowRight = canSwipeRight(touchState.id);
- const allowLeft = canSwipeLeft(touchState.id);
+ const { allowRight, allowLeft } = touchState;
// Constrain dx based on available callbacks
let constrainedDx = dx;
@@ -416,9 +442,7 @@ export function SwipableRowProvider(
const deltaX = touchState.currentX - touchState.startX;
const entityId = touchState.id;
-
- const allowRight = canSwipeRight(entityId);
- const allowLeft = canSwipeLeft(entityId);
+ const { allowRight, allowLeft } = touchState;
if (allowRight && deltaX > SWIPE_ACTIVATION_DISTANCE) {
void handleSwipe(entityId);
diff --git a/apps/web/src/components/app/split-layout/mobile/createMobileSplitMotion.ts b/apps/web/src/components/app/split-layout/mobile/createMobileSplitMotion.ts
index 89678e69a6..a55b236511 100644
--- a/apps/web/src/components/app/split-layout/mobile/createMobileSplitMotion.ts
+++ b/apps/web/src/components/app/split-layout/mobile/createMobileSplitMotion.ts
@@ -5,7 +5,8 @@ import { createMobileForwardAnimation } from './createMobileForwardAnimation';
import type { MobilePaneStack } from './createMobilePaneStack';
import { createMobileSwipeBackGesture } from './createMobileSwipeBackGesture';
-const SWIPE_EDGE_THRESHOLD = 40; // px from left edge to initiate gesture
+/** Px from the left edge where a touch starts the swipe-back gesture. */
+export const SWIPE_EDGE_THRESHOLD = 40;
const SWIPE_VELOCITY_THRESHOLD = 0.3; // px/ms - fast flick completes swipe
const SWIPE_DISTANCE_THRESHOLD = 0.5; // fraction of screen width
const SWIPE_ANIMATION_MS = 88;
diff --git a/apps/web/src/features/email-view/components/EmailList.tsx b/apps/web/src/features/email-view/components/EmailList.tsx
index d79accf9d2..66fa03b655 100644
--- a/apps/web/src/features/email-view/components/EmailList.tsx
+++ b/apps/web/src/features/email-view/components/EmailList.tsx
@@ -27,6 +27,7 @@ import {
ListLayoutProvider,
type WithNotification,
} from '@entity';
+import BellIcon from '@phosphor/bell-simple.svg';
import CaretDownIcon from '@phosphor/caret-down.svg';
import CheckIcon from '@phosphor/check.svg';
import SpinnerIcon from '@phosphor/spinner.svg';
@@ -301,10 +302,14 @@ export function EmailList(props: EmailListProps) {
});
}
- const markDoneActionFor = (row: EmailActionRow) =>
+ const rowActionFor = (row: EmailActionRow, id: string) =>
actionGroupsFor(row)
.flatMap((group) => group.items)
- .find((action) => action.id === 'mark-done');
+ .find((action) => action.id === id);
+ const markDoneActionFor = (row: EmailActionRow) =>
+ rowActionFor(row, 'mark-done');
+ const remindActionFor = (row: EmailActionRow) =>
+ rowActionFor(row, 'create-reminder');
function focusActionRow(row: EmailActionRow) {
list.focus.set(row.rowId, { reason: 'pointer', force: true });
@@ -477,6 +482,22 @@ export function EmailList(props: EmailListProps) {
focusActionRow(row);
void action.onClick();
}}
+ canSwipeRight={(entityId) => {
+ const row = swipeRowsByEntityId().get(entityId);
+ return row ? remindActionFor(row) !== undefined : false;
+ }}
+ onSwipeRight={(entityId) => {
+ const row = swipeRowsByEntityId().get(entityId);
+ if (!row) return;
+
+ const action = remindActionFor(row);
+ if (!action) return;
+
+ focusActionRow(row);
+ void action.onClick();
+ }}
+ // Done removes the row; Remind me keeps it until a time is picked.
+ triggerBehavior={{ left: 'fly-out', right: 'spring-back' }}
>
<Switch>
<Match
@@ -671,6 +692,10 @@ export function EmailList(props: EmailListProps) {
swipeLeftRevealedComponent: (
<CheckIcon class="size-8 text-surface" />
),
+ swipeRightColor: 'bg-accent',
+ swipeRightRevealedComponent: (
+ <BellIcon class="size-8 text-surface" />
+ ),
}}
onClick={(event) => {
if (
diff --git a/apps/web/src/features/reminders/components/email-reminder-form.tsx b/apps/web/src/features/reminders/components/email-reminder-form.tsx
index 6194d8c33e..900912e5ea 100644
--- a/apps/web/src/features/reminders/components/email-reminder-form.tsx
+++ b/apps/web/src/features/reminders/components/email-reminder-form.tsx
@@ -126,8 +126,9 @@ export function EmailReminderForm(
</Show>
</CommandMenuShell.Body>
{/* p-2 insets the h-8 pill so its 16px radius stays concentric
- with the dialog's 24px corner. */}
- <CommandMenuShell.Footer class="grid grid-cols-[1fr_auto_1fr] gap-2 p-2">
+ with the dialog's 24px corner. Touch has no keyboard hint, and a
+ phone is too narrow for fixed thirds, so the row wraps instead. */}
+ <CommandMenuShell.Footer class="grid grid-cols-[1fr_auto_1fr] gap-2 p-2 touch:flex touch:flex-wrap touch:items-center touch:justify-between">
<div class="flex items-center gap-1 justify-self-start">
<Button
variant="ghost"
@@ -152,11 +153,20 @@ export function EmailReminderForm(
</Show>
</div>
<span role="status" class="min-w-0 truncate text-center">
- {props.pending ? 'Saving…' : '↑ ↓ to choose · Enter to snooze'}
+ <Show
+ when={props.pending}
+ fallback={
+ <span class="touch:hidden">
+ ↑ ↓ to choose · Enter to snooze
+ </span>
+ }
+ >
+ Saving…
+ </Show>
</span>
<SegmentedControl<EmailReminderCondition>
aria-label="Reminder condition"
- class="justify-self-end"
+ class="justify-self-end whitespace-nowrap touch:ml-auto"
value={props.condition}
onChange={props.onConditionChange}
options={[
diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.md
index 7a42de8e8d..596b4a356d 100644
--- a/docs/agent-guide/email.md
+++ b/docs/agent-guide/email.md
@@ -52,7 +52,9 @@ replace the timestamp within its existing space. Archived rows offer
**Unarchive email**; the archive control is disabled in tabs that do not support
Mark Done. The icons also appear when a button receives keyboard focus. Clicking
an icon neither opens the thread nor applies the action to other selected rows.
-Touch devices retain the swipe actions.
+On touch devices, swiping a row left marks it done and swiping right opens
+**Remind me** for it; the row springs back until a time is picked. Right swipes
+that start within 40px of the left edge are left to swipe-back navigation.
Search results use the same reserved column, with actions aligned to the first
line; snippets, highlighted matches, and expanded hits remain unobstructed.
diff --git a/docs/agent-guide/reminders.md b/docs/agent-guide/reminders.md
index 7e03559755..bc03ab4f7d 100644
--- a/docs/agent-guide/reminders.md
+++ b/docs/agent-guide/reminders.md
@@ -98,3 +98,5 @@ verify the conversation is in the newest time group without reloading. Repeat
with an older conversation, a sent-only conversation, and a backgrounded tab.
Also verify reply cancellation, caller isolation, multiple concurrent set
requests, filtered pagination, desktop keyboard interaction, and a narrow viewport.
+On a phone (touch, about 320–390px wide) the menu's footer keeps the If no reply
+/ Regardless control on one line beside Cancel, with no keyboard hint.