Skip to content
TypeScript

fix(mobile): drafts swipe to discard and every row move animates (#23205)

Julius Marmingeb295dd83b2f9
diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx
index 02688d85df5..e8a9ac35e34 100644
--- a/apps/mobile/src/features/home/HomeScreen.tsx
+++ b/apps/mobile/src/features/home/HomeScreen.tsx
@@ -593,6 +593,11 @@ export function HomeScreen(props: HomeScreenProps) {
showTrailingDivider={item.showTrailingDivider}
onSelectPendingTask={props.onSelectPendingTask}
onDeletePendingTask={props.onDeletePendingTask}
+ fullSwipeWidth={fullSwipeWidth}
+ onSwipeableClose={handleSwipeableClose}
+ onSwipeableWillOpen={handleSwipeableWillOpen}
+ simultaneousSwipeGesture={homeScrollGesture}
+ activationKey={item.key}
/>
);
}
diff --git a/apps/mobile/src/features/home/thread-swipe-actions.tsx b/apps/mobile/src/features/home/thread-swipe-actions.tsx
index a320e7b21e3..33c4a44d052 100644
--- a/apps/mobile/src/features/home/thread-swipe-actions.tsx
+++ b/apps/mobile/src/features/home/thread-swipe-actions.tsx
@@ -62,6 +62,7 @@ interface ThreadSwipeAction {
readonly accessibilityLabel: string;
readonly icon: ComponentProps<typeof SymbolView>["name"];
readonly label: string;
+ readonly destructive?: boolean;
readonly menu?: {
readonly actions: MenuAction[];
readonly onPressAction: NonNullable<ComponentProps<typeof Menu>["onPressAction"]>;
@@ -726,7 +727,7 @@ export function ThreadSwipeActions(props: {
<SwipeActionButton
accessibilityLabel={props.primaryAction.accessibilityLabel}
actionsWidth={actionsWidth}
- tone="primary"
+ tone={props.primaryAction.destructive === true ? "danger" : "primary"}
compact={props.compact}
entryRange={
secondaryAction === null
diff --git a/apps/mobile/src/features/home/usePendingTaskListActions.ts b/apps/mobile/src/features/home/usePendingTaskListActions.ts
index 20fba857a71..ff3572811cc 100644
--- a/apps/mobile/src/features/home/usePendingTaskListActions.ts
+++ b/apps/mobile/src/features/home/usePendingTaskListActions.ts
@@ -5,7 +5,13 @@ import { useCallback } from "react";
import { removeThreadOutboxMessage } from "../../state/thread-outbox-removal";
import { clearComposerDraftContent } from "../../state/use-composer-drafts";
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
-import { releaseEditingQueuedMessage } from "../../state/use-thread-outbox";
+import { appAtomRegistry } from "../../state/atom-registry";
+import {
+ editingQueuedMessageIdsAtom,
+ holdEditingQueuedMessage,
+ releaseEditingQueuedMessage,
+} from "../../state/use-thread-outbox";
+import { withThreadDismissal } from "./thread-dismissal";
export function usePendingTaskListActions(): {
readonly openPendingTask: (pendingTask: PendingNewTask) => void;
@@ -37,10 +43,15 @@ export function usePendingTaskListActions(): {
text: "Discard",
style: "destructive",
onPress: () => {
- clearComposerDraftContent(pendingTask.draftKey, {
- clearModelSelection: true,
- clearWorkspaceSelection: true,
- });
+ void withThreadDismissal(
+ pendingTask.key,
+ async () =>
+ clearComposerDraftContent(pendingTask.draftKey, {
+ clearModelSelection: true,
+ clearWorkspaceSelection: true,
+ }),
+ () => true,
+ );
},
},
]);
@@ -55,12 +66,28 @@ export function usePendingTaskListActions(): {
text: "Delete",
style: "destructive",
onPress: () => {
- // Release the edit lock only after removal succeeds, and only if
- // it is held for THIS task — clearing it up front (or for another
- // task) would let the drain deliver a mid-edit payload.
- void removeThreadOutboxMessage(pendingTask.message)
- .then(() => releaseEditingQueuedMessage(pendingTask.message.messageId))
+ // The row animates out before removal runs, so hold delivery from
+ // confirmation on: a reconnect must not send a task being deleted.
+ // The hold is shared with the editor, which could release it
+ // mid-animation, so a task open in the editor is removed at once
+ // and keeps its hold unless removal succeeds.
+ const messageId = pendingTask.message.messageId;
+ const heldByEditor = appAtomRegistry.get(editingQueuedMessageIdsAtom)[messageId];
+ holdEditingQueuedMessage(messageId);
+ const releaseUnlessEditing = () => {
+ if (!heldByEditor) releaseEditingQueuedMessage(messageId);
+ };
+ const remove = () => removeThreadOutboxMessage(pendingTask.message);
+ void (
+ heldByEditor
+ ? remove()
+ : withThreadDismissal(pendingTask.key, remove, (removed) => removed)
+ )
+ .then((removed) =>
+ removed ? releaseEditingQueuedMessage(messageId) : releaseUnlessEditing(),
+ )
.catch((error) => {
+ releaseUnlessEditing();
Dialog.alert(
"Could not delete pending task",
error instanceof Error ? error.message : "The pending task could not be removed.",
diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts
index 837887a73d6..0f18f24923c 100644
--- a/apps/mobile/src/features/home/useThreadListActions.ts
+++ b/apps/mobile/src/features/home/useThreadListActions.ts
@@ -456,10 +456,15 @@ export function useThreadListActions(): {
// Pinning clears snooze, so older Settled or Snoozed undos would fight this pin.
ThreadUndo.invalidate("settle", scopedThreadKey(thread.environmentId, thread.id));
ThreadUndo.invalidate("snooze", scopedThreadKey(thread.environmentId, thread.id));
- const result = await pinMutation({
- environmentId: thread.environmentId,
- input: { threadId: thread.id, ...(orderKey !== undefined ? { orderKey } : {}) },
- });
+ const result = await withThreadDismissal(
+ scopedThreadKey(thread.environmentId, thread.id),
+ () =>
+ pinMutation({
+ environmentId: thread.environmentId,
+ input: { threadId: thread.id, ...(orderKey !== undefined ? { orderKey } : {}) },
+ }),
+ (result) => result._tag === "Success",
+ );
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
Dialog.alert(
@@ -484,10 +489,15 @@ export function useThreadListActions(): {
selectionHaptic();
const plan = ThreadUndo.planThreadUndo("unpin", thread);
const claim = ThreadUndo.begin("pin", scopedThreadKey(thread.environmentId, thread.id));
- const result = await unpinMutation({
- environmentId: thread.environmentId,
- input: { threadId: thread.id },
- });
+ const result = await withThreadDismissal(
+ scopedThreadKey(thread.environmentId, thread.id),
+ () =>
+ unpinMutation({
+ environmentId: thread.environmentId,
+ input: { threadId: thread.id },
+ }),
+ (result) => result._tag === "Success",
+ );
if (result._tag === "Failure") {
claim.finish();
const error = Cause.squash(result.cause);
diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
index 9813f0d4633..96e80c44a72 100644
--- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
@@ -585,6 +585,10 @@ function ThreadNavigationSidebarPane(
showPendingDivider={item.showPendingDivider}
onSelectPendingTask={props.onOpenPendingTask}
onDeletePendingTask={confirmDeletePendingTask}
+ fullSwipeWidth={props.width - 20}
+ onSwipeableClose={handleSwipeableClose}
+ onSwipeableWillOpen={handleSwipeableWillOpen}
+ simultaneousSwipeGesture={sidebarScrollGesture}
/>
);
}
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 d072c17aa71..4fb1275b895 100644
--- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx
+++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx
@@ -325,10 +325,34 @@ export const ThreadListV2PendingRow = memo(function ThreadListV2PendingRow(props
readonly showTrailingDivider?: boolean;
readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
+ readonly fullSwipeWidth?: number;
+ readonly onSwipeableWillOpen: (methods: SwipeableMethods) => void;
+ readonly onSwipeableClose: (methods: SwipeableMethods) => void;
+ readonly activationKey?: string;
+ readonly simultaneousSwipeGesture?: ComponentProps<typeof ThreadSwipeable>["simultaneousWith"];
}) {
const { pendingTask, onSelectPendingTask, onDeletePendingTask } = props;
+ const { width: windowWidth } = useWindowDimensions();
+ const dormant = useSwipeRowDormant(props.activationKey);
+ const theme = useUniwindTheme();
const sidebarPane = props.pane === "sidebar";
+ const rowAppearance = getThreadListV2RowAppearance(theme, sidebarPane, false);
const isDraft = pendingTask.kind === "draft";
+ const deleteLabel = isDraft ? "Discard" : "Delete";
+ const handleDelete = useCallback(
+ () => onDeletePendingTask(pendingTask),
+ [onDeletePendingTask, pendingTask],
+ );
+ const deleteAction = useMemo(
+ () => ({
+ accessibilityLabel: `${deleteLabel} ${pendingTask.title}`,
+ destructive: true,
+ icon: "trash" as const,
+ label: deleteLabel,
+ onPress: handleDelete,
+ }),
+ [deleteLabel, handleDelete, pendingTask.title],
+ );
const projectTitle = props.projectTitle ?? props.project?.title ?? pendingTask.projectTitle ?? "";
const branch = pendingTask.branch;
@@ -442,45 +466,65 @@ export const ThreadListV2PendingRow = memo(function ThreadListV2PendingRow(props
{props.showPendingDivider ? (
<ThreadListV2SectionDivider label="Unsent" pane={props.pane} />
) : null}
- <Menu
- actions={isDraft ? DRAFT_TASK_MENU_ACTIONS : PENDING_TASK_MENU_ACTIONS}
- onPressAction={handleMenuAction}
- shouldOpenOnLongPress
+ <ThreadSwipeable
+ dormant={dormant}
+ threadKey={pendingTask.key}
+ backgroundColor={rowAppearance.swipeBackgroundColor}
+ containerStyle={rowAppearance.swipeContainerStyle}
+ enableTrackpadSwipe
+ fullSwipeAction="primary"
+ fullSwipeWidth={props.fullSwipeWidth ?? windowWidth - 32}
+ onDelete={handleDelete}
+ onSwipeableClose={props.onSwipeableClose}
+ onSwipeableWillOpen={props.onSwipeableWillOpen}
+ primaryAction={deleteAction}
+ secondaryAction={null}
+ resetKey={pendingTask.key}
+ simultaneousWith={props.simultaneousSwipeGesture}
+ threadTitle={pendingTask.title}
>
- <RowPressable
- accessibilityHint={
- isDraft
- ? "Opens the draft in the new task composer"
- : "Sends when the environment reconnects. Opens the task for editing"
- }
- accessibilityLabel={pendingTask.title}
- accessibilityRole="button"
- key={pendingTask.key}
- className={sidebarPane ? "bg-drawer" : "bg-screen"}
- interactionClassName={sidebarPane ? "bg-thread-hover" : "bg-row-hover"}
- onPress={() => onSelectPendingTask(pendingTask)}
- style={
- sidebarPane
- ? {
- borderRadius: SIDEBAR_V2_ROW_RADIUS,
- paddingHorizontal: 12,
- paddingVertical: 10,
- }
- : undefined
- }
- >
- {sidebarPane ? (
- rowContent
- ) : (
- <View>
- <View className="px-5 py-2.5">{rowContent}</View>
- {props.showTrailingDivider !== false ? (
- <View className="ml-5 h-px bg-border-subtle" />
- ) : null}
- </View>
- )}
- </RowPressable>
- </Menu>
+ {() => (
+ <Menu
+ actions={isDraft ? DRAFT_TASK_MENU_ACTIONS : PENDING_TASK_MENU_ACTIONS}
+ onPressAction={handleMenuAction}
+ shouldOpenOnLongPress
+ >
+ <RowPressable
+ accessibilityHint={
+ isDraft
+ ? `Opens the draft in the new task composer. Swipe left to ${deleteLabel.toLowerCase()}.`
+ : `Sends when the environment reconnects. Opens the task for editing. Swipe left to ${deleteLabel.toLowerCase()}.`
+ }
+ accessibilityLabel={pendingTask.title}
+ accessibilityRole="button"
+ key={pendingTask.key}
+ className={sidebarPane ? "bg-drawer" : "bg-screen"}
+ interactionClassName={sidebarPane ? "bg-thread-hover" : "bg-row-hover"}
+ onPress={() => onSelectPendingTask(pendingTask)}
+ style={
+ sidebarPane
+ ? {
+ borderRadius: SIDEBAR_V2_ROW_RADIUS,
+ paddingHorizontal: 12,
+ paddingVertical: 10,
+ }
+ : undefined
+ }
+ >
+ {sidebarPane ? (
+ rowContent
+ ) : (
+ <View>
+ <View className="px-5 py-2.5">{rowContent}</View>
+ {props.showTrailingDivider !== false ? (
+ <View className="ml-5 h-px bg-border-subtle" />
+ ) : null}
+ </View>
+ )}
+ </RowPressable>
+ </Menu>
+ )}
+ </ThreadSwipeable>
</>
);
});
@@ -1334,7 +1378,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
onSwipeableWillOpen={props.onSwipeableWillOpen}
primaryAction={primaryAction}
secondaryAction={secondaryAction}
- resetKey={`${thread.environmentId}:${thread.id}:${variant}:${snoozedRow}:${thread.settledAt}:${thread.unsettledAt}:${thread.snoozedUntil}`}
+ resetKey={`${thread.environmentId}:${thread.id}:${variant}:${snoozedRow}:${thread.settledAt}:${thread.unsettledAt}:${thread.snoozedUntil}:${thread.pinnedAt}`}
simultaneousWith={props.simultaneousSwipeGesture}
threadTitle={thread.title}
>