Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

thread-list-v2-items.tsx

1,171 lines43.3 KB

1import {
2 THREAD_LIST_V2_MONO_FONT as MONO_FONT,
3 THREAD_LIST_V2_ROW_CONTENT_CLASS_NAME,
4 THREAD_LIST_V2_ROW_DIVIDERS,
5 selectedThreadRowColors,
6 getThreadListV2NewBranchMenuTitle,
7 getThreadListV2RowAppearance,
8} from "./thread-list-v2-row-appearance";
9import { RowPressable } from "../../components/RowPressable";
10import { CustomSnoozeSheet } from "./CustomSnoozeSheet";
11import { appAtomRegistry } from "../../state/atom-registry";
12import { threadArrangementOpenAtom } from "../../state/thread-order";
13import type { ThreadMoveDestination } from "./threadOrder";
14import type {
15 EnvironmentProject,
16 EnvironmentThreadShell,
17} from "@t3tools/client-runtime/state/shell";
18import type { EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
19import type { EnvironmentMachineKind } from "@t3tools/contracts";
20import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
21import { resolveSettledThreadTimestamp } from "@t3tools/client-runtime/state/thread-sort";
22import type { MenuAction } from "@react-native-menu/menu";
23import { memo, useCallback, useEffect, useMemo, useState, type ComponentProps } from "react";
24import { Alert, Pressable, useWindowDimensions, View } from "react-native";
25import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
26​
27import { SymbolView } from "../../components/AppSymbol";
28import { AppText as Text } from "../../components/AppText";
29import { ControlPillMenu } from "../../components/ControlPill";
30import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
31import { ProjectFavicon } from "../../components/ProjectFavicon";
32import { ProviderInstanceIcon } from "../../components/ProviderIcon";
33import type { ThreadRowProviderInstance } from "./thread-provider-instance";
34import { cn } from "../../lib/cn";
35import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
36import { relativeTime } from "../../lib/time";
37import { useUniwindTheme } from "../../lib/useUniwindTheme";
38import type { PendingNewTask } from "../../state/use-pending-new-tasks";
39import { useThreadPr } from "../../state/use-thread-pr";
40import { ThreadSwipeable } from "../home/thread-swipe-actions";
41import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
42import {
43 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
44 resolveThreadListV2SnoozeMenuSelection,
45 resolveThreadListV2SnoozeGateExpiryMs,
46 resolveThreadListV2Status,
47 resolveThreadListV2SwipeActions,
48 type ThreadListV2Status,
49} from "./threadListV2";
50import { QueuedMessageIcon } from "./queued-message-icon";
51import { ThreadSearchMatchExcerpt } from "./thread-search-match";
52​
53/**
54 * Thread List v2 renders one flat native list: rich edge-to-edge rows for
55 * active work and a receded settled tail, all with native swipe and
56 * long-press actions. State reads through colored status labels and text
57 * hierarchy rather than card fills.
58 */
59​
60// Status hues follow the system-wide convention set by sidebar v1 and the
61// Live Activity/widgets (amber approval, indigo input, sky working) so a
62// thread reads the same color everywhere it surfaces.
63const STATUS_LABEL_BY_STATUS: Partial<
64 Record<ThreadListV2Status, { label: string; className: string }>
65> = {
66 approval: { label: "Approval", className: "text-warning-foreground" },
67 input: { label: "Input", className: "text-adaptive-indigo-600-300" },
68 working: { label: "Working", className: "text-adaptive-sky-600-400" },
69 failed: { label: "Failed", className: "text-danger-foreground" },
70};
71​
72function threadTimeLabel(thread: EnvironmentThreadShell): string {
73 return relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt);
75​
76// Menus keep lifecycle and title regeneration together. Archive keeps its
77// own surface (thread screen / settings) rather than crowding v2 rows.
78const CARD_MENU_ACTIONS: MenuAction[] = [
79 { id: "settle", title: "Settle", image: "checkmark" },
80 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
81];
82​
83const SLIM_MENU_ACTIONS: MenuAction[] = [
84 { id: "unsettle", title: "Un-settle", image: "arrow.uturn.backward" },
85 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
86];
87​
88const SNOOZED_MENU_ACTIONS: MenuAction[] = [
89 { id: "unsnooze", title: "Wake thread", image: "clock" },
90 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
91];
92​
93// Pre-settlement servers: no lifecycle items, archive fills the gap.
94const LEGACY_MENU_ACTIONS: MenuAction[] = [
95 { id: "archive", title: "Archive", image: "archivebox" },
96 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
97];
98​
99/** Rounded-row radius shared with the v1 sidebar rows. */
100const SIDEBAR_V2_ROW_RADIUS = 12;
101​
102function ThreadListV2Section(props: {
103 readonly label: string;
104 readonly pane?: "screen" | "sidebar";
105 readonly tone?: "default" | "snoozed";
106 readonly disclosure?: {
107 readonly expanded: boolean;
108 readonly disabled?: boolean;
109 readonly onToggle: () => void;
110 readonly accessibilityLabel: string;
111 readonly accessibilityHint: string;
112 };
113}) {
114 const snoozed = props.tone === "snoozed";
115 const sidebarPane = props.pane === "sidebar";
116 const className = cn(
117 "mb-1.5 mt-4 flex-row items-center gap-2.5",
118 props.pane === "sidebar" ? "px-3" : "px-5",
119 );
120 const content = (
121 <>
122 <Text
123 className={cn(
124 "text-xs font-t3-medium",
125 sidebarPane
126 ? "text-drawer-foreground-muted"
127 : snoozed
128 ? "text-foreground-secondary"
129 : "text-foreground-tertiary",
130 )}
131 >
132 {props.label}
133 </Text>
134 <View
135 className={cn(
136 "h-px flex-1",
137 snoozed ? "bg-primary/20" : sidebarPane ? "bg-drawer-border" : "bg-border",
138 )}
139 />
140 {props.disclosure ? (
141 <SymbolView
142 name="chevron.down"
143 size={10}
144 tintColorClassName={
145 sidebarPane
146 ? "accent-drawer-foreground-muted"
147 : snoozed
148 ? "accent-icon-muted"
149 : "accent-foreground-muted"
150 }
151 type="monochrome"
152 style={{ transform: [{ rotate: props.disclosure.expanded ? "180deg" : "0deg" }] }}
153 />
154 ) : null}
155 </>
156 );
157​
158 return props.disclosure ? (
159 <Pressable
160 accessibilityHint={props.disclosure.accessibilityHint}
161 accessibilityLabel={props.disclosure.accessibilityLabel}
162 accessibilityRole="button"
163 accessibilityState={{
164 disabled: props.disclosure.disabled,
165 expanded: props.disclosure.expanded,
166 }}
167 className={className}
168 disabled={props.disclosure.disabled}
169 onPress={props.disclosure.onToggle}
170 style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
171 >
172 {content}
173 </Pressable>
174 ) : (
175 <View className={className}>{content}</View>
176 );
178​
179/** Section label + rule: the only structure in an otherwise flat list. */
180export const ThreadListV2SectionDivider = memo(function ThreadListV2SectionDivider(props: {
181 readonly label: string;
182 readonly pane?: "screen" | "sidebar";
183}) {
184 return <ThreadListV2Section {...props} />;
185});
186​
187type ThreadListV2ShelfHeaderProps = {
188 readonly count: number;
189 readonly disabled?: boolean;
190 readonly expanded: boolean;
191 readonly onToggle: () => void;
192 readonly pane?: "screen" | "sidebar";
193};
194​
195function ThreadListV2ShelfHeader(
196 props: ThreadListV2ShelfHeaderProps & { readonly kind: "snoozed" | "settled" },
197) {
198 const label = props.kind === "snoozed" ? "Snoozed" : "Settled";
199 return (
200 <ThreadListV2Section
201 label={props.expanded ? label : `${label} (${props.count})`}
202 pane={props.pane}
203 tone={props.kind === "snoozed" ? "snoozed" : "default"}
204 disclosure={{
205 expanded: props.expanded,
206 disabled: props.disabled,
207 onToggle: props.onToggle,
208 accessibilityLabel: `${props.count} ${props.kind} ${props.count === 1 ? "thread" : "threads"}`,
209 accessibilityHint: `${props.expanded ? "Collapses" : "Expands"} the ${props.kind} threads.`,
210 }}
211 />
212 );
214​
215export const ThreadListV2SnoozedShelfHeader = memo(function ThreadListV2SnoozedShelfHeader(
216 props: ThreadListV2ShelfHeaderProps,
217) {
218 return <ThreadListV2ShelfHeader {...props} kind="snoozed" />;
219});
220​
221export const ThreadListV2SettledShelfHeader = memo(function ThreadListV2SettledShelfHeader(
222 props: ThreadListV2ShelfHeaderProps,
223) {
224 return <ThreadListV2ShelfHeader {...props} kind="settled" />;
225});
226​
227export const ThreadListV2ShowMoreRow = memo(function ThreadListV2ShowMoreRow(props: {
228 readonly pane?: "screen" | "sidebar";
229 readonly hiddenCount: number;
230 readonly onPress: () => void;
231}) {
232 return (
233 <Pressable
234 accessibilityRole="button"
235 accessibilityLabel={`Show ${Math.min(props.hiddenCount, THREAD_LIST_V2_SETTLED_PAGE_COUNT)} more settled threads`}
236 onPress={props.onPress}
237 className="mx-4 mt-2 items-center rounded-lg border border-dashed border-border py-2.5"
238 style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
239 >
240 <Text
241 className={
242 props.pane === "sidebar"
243 ? "text-xs font-t3-medium text-drawer-foreground-muted"
244 : "text-xs font-t3-medium text-foreground-muted"
245 }
246 >
247 Show more ({props.hiddenCount} settled hidden)
248 </Text>
249 </Pressable>
250 );
251});
252​
253const PENDING_TASK_MENU_ACTIONS: MenuAction[] = [
254 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
255];
256​
257const DRAFT_TASK_MENU_ACTIONS: MenuAction[] = [
258 { id: "delete", title: "Discard", image: "trash", attributes: { destructive: true } },
259];
260​
261/**
262 * Unsent work, in the same idiom as an active v2 row: it is work the user
263 * wrote, so it reads like the thread it will become. The status slot says
264 * what happens next, not where the item sits: "Sends on reconnect" stays
265 * uncolored because nothing is asked of the user; "Draft" takes the amber the
266 * web sidebar uses for drafts, because this one waits on the user.
267 */
268export const ThreadListV2PendingRow = memo(function ThreadListV2PendingRow(props: {
269 readonly pendingTask: PendingNewTask;
270 readonly project: EnvironmentProject | null;
271 readonly projectTitle?: string;
272 readonly environmentLabel: string | null;
273 /** Drawn beside the label; ignored while the label is null. */
274 readonly environmentMachine?: EnvironmentMachineKind;
275 readonly pane?: "screen" | "sidebar";
276 /** Draws the "Unsent" divider above the first draft or queued row. */
277 readonly showPendingDivider: boolean;
278 /** Keeps row hairlines inside a section; section headers draw their own rule. */
279 readonly showTrailingDivider?: boolean;
280 readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
281 readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
282}) {
283 const { pendingTask, onSelectPendingTask, onDeletePendingTask } = props;
284 const sidebarPane = props.pane === "sidebar";
285 const isDraft = pendingTask.kind === "draft";
286 const projectTitle = props.projectTitle ?? props.project?.title ?? pendingTask.projectTitle ?? "";
287 const branch = pendingTask.branch;
288​
289 const handleMenuAction = useCallback(
290 ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
291 if (nativeEvent.event === "delete") onDeletePendingTask(pendingTask);
292 },
293 [onDeletePendingTask, pendingTask],
294 );
295​
296 const rowContent = (
297 <>
298 <View className="flex-row items-center gap-1.5">
299 {props.project ? (
300 <ProjectFavicon
301 environmentId={pendingTask.environmentId}
302 faviconPath={props.project.faviconPath}
303 size={15}
304 projectTitle={projectTitle}
305 workspaceRoot={props.project.workspaceRoot}
306 />
307 ) : null}
308 <Text
309 className={cn(
310 "flex-1 text-sm font-t3-medium text-foreground-muted",
311 sidebarPane && "text-drawer-foreground-muted",
312 )}
313 numberOfLines={1}
314 >
315 {projectTitle}
316 </Text>
317 {isDraft ? (
318 <View className="flex-row items-center gap-1">
319 <SymbolView
320 name="square.and.pencil"
321 size={10}
322 tintColorClassName="accent-adaptive-amber-700-300"
323 type="monochrome"
324 />
325 <Text className="text-xs text-adaptive-amber-700-300">Draft</Text>
326 </View>
327 ) : (
328 <Text
329 className={cn(
330 "text-xs text-foreground-tertiary",
331 sidebarPane && "text-drawer-foreground-muted",
332 )}
333 >
334 Sends on reconnect
335 </Text>
336 )}
337 </View>
338 {/* One line, unlike the two an active row allows: a queued title is
339 derived from the whole prompt rather than written as a title, so the
340 second line is usually a stray word or emoji rather than meaning. */}
341 <Text
342 className={cn(
343 "mt-1 text-base font-t3-medium text-foreground",
344 sidebarPane && "text-drawer-foreground",
345 )}
346 numberOfLines={1}
347 >
348 {pendingTask.title}
349 </Text>
350 {branch || props.environmentLabel ? (
351 <View className="mt-1 flex-row items-center gap-1">
352 <Text
353 className={cn(
354 "shrink text-xs text-foreground-muted",
355 sidebarPane && "text-drawer-foreground-muted",
356 )}
357 numberOfLines={1}
358 >
359 {branch ? (
360 <Text
361 className={cn(
362 "text-xs text-foreground-muted",
363 sidebarPane && "text-drawer-foreground-muted",
364 )}
365 style={{ fontFamily: MONO_FONT }}
366 >
367 {branch}
368 </Text>
369 ) : null}
370 {branch && props.environmentLabel ? " · " : null}
371 {props.environmentLabel ? (
372 <Text
373 className={cn(
374 "text-xs text-foreground-tertiary",
375 sidebarPane && "text-drawer-foreground-muted",
376 )}
377 >
378 {props.environmentLabel}
379 </Text>
380 ) : null}
381 </Text>
382 {props.environmentLabel && props.environmentMachine ? (
383 <EnvironmentMachineSymbol
384 kind={props.environmentMachine}
385 size={11}
386 tintColorClassName={
387 sidebarPane ? "accent-drawer-foreground-muted" : "accent-foreground-tertiary"
388 }
389 />
390 ) : null}
391 </View>
392 ) : null}
393 </>
394 );
395​
396 return (
397 <>
398 {props.showPendingDivider ? (
399 <ThreadListV2SectionDivider label="Unsent" pane={props.pane} />
400 ) : null}
401 <ControlPillMenu
402 actions={isDraft ? DRAFT_TASK_MENU_ACTIONS : PENDING_TASK_MENU_ACTIONS}
403 onPressAction={handleMenuAction}
404 shouldOpenOnLongPress
405 >
406 <RowPressable
407 accessibilityHint={
408 isDraft
409 ? "Opens the draft in the new task composer"
410 : "Sends when the environment reconnects. Opens the task for editing"
411 }
412 accessibilityLabel={pendingTask.title}
413 accessibilityRole="button"
414 key={pendingTask.key}
415 className={sidebarPane ? "bg-drawer" : "bg-screen"}
416 interactionClassName={sidebarPane ? "bg-thread-hover" : "bg-row-hover"}
417 onPress={() => onSelectPendingTask(pendingTask)}
418 style={
419 sidebarPane
420 ? {
421 borderRadius: SIDEBAR_V2_ROW_RADIUS,
422 paddingHorizontal: 12,
423 paddingVertical: 10,
424 }
425 : undefined
426 }
427 >
428 {sidebarPane ? (
429 rowContent
430 ) : (
431 <View>
432 <View className="px-5 py-2.5">{rowContent}</View>
433 {props.showTrailingDivider !== false ? (
434 <View className="ml-5 h-px bg-border-subtle" />
435 ) : null}
436 </View>
437 )}
438 </RowPressable>
439 </ControlPillMenu>
440 </>
441 );
442});
443​
444export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
445 readonly thread: EnvironmentThreadShell;
446 readonly variant: "card" | "slim";
447 /** A message for this thread is waiting in the outbox. */
448 readonly hasQueuedMessages?: boolean;
449 /** Snoozed-shelf row: shows its wake time and offers Wake. */
450 readonly snoozed?: boolean;
451 /** Pinned-block row: shows the pin glyph and offers Unpin. */
452 readonly pinned?: boolean;
453 /** Preformatted against the parent minute tick so this memoized row's
454 countdown keeps moving. */
455 readonly snoozeWakeLabelText?: string;
456 /** Parent minute tick passed as a prop so this memoized row refreshes its
457 native snooze menu while mounted. */
458 readonly snoozePresetMinute: string;
459 readonly project: EnvironmentProject | null;
460 readonly projectTitle?: string;
461 readonly providerInstance: ThreadRowProviderInstance | null;
462 /** Which machine hosts the thread. Null when only one environment is
463 connected — repeating the same label on every row is noise. Mirrors
464 the web sidebar's remote-environment cloud icon, but as text since
465 phones have no hover tooltips. */
466 readonly environmentLabel: string | null;
467 /** Drawn after the label so the machine reads at a glance; ignored while
468 the label is null. */
469 readonly environmentMachine?: EnvironmentMachineKind;
470 /** Hosting surface. "screen" (default) renders the compact Home idiom:
471 flat edge-to-edge rows on the screen background with inset hairlines.
472 "sidebar" renders the iPad split-view idiom: rounded rows blending
473 into the drawer surface, selection filled with the accent color —
474 matching the v1 sidebar rows. */
475 readonly pane?: "screen" | "sidebar";
476 /** Keeps row hairlines inside a section; section headers draw their own rule. */
477 readonly showTrailingDivider?: boolean;
478 /** Highlights the thread open in the detail pane (iPad split view). The
479 compact Home list never sets it — phones navigate away on select. */
480 readonly selected?: boolean;
481 /** Override for narrow panes (iPad sidebar); defaults to window width. */
482 readonly fullSwipeWidth?: number;
483 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
484 readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
485 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
486 readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
487 readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => void;
488 readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
489 readonly onSnoozeThread: (thread: EnvironmentThreadShell, snoozedUntil: string) => void;
490 readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => void;
491 readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
492 readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
493 readonly onPinThread: (thread: EnvironmentThreadShell) => void;
494 readonly onUnpinThread: (thread: EnvironmentThreadShell) => void;
495 /** False on environments whose server predates thread.settle/unsettle:
496 swipe + menu fall back to Archive instead of failing on use. */
497 readonly settlementSupported: boolean;
498 /** False on servers that predate thread.snooze/unsnooze. */
499 readonly snoozeSupported: boolean;
500 /** False on servers that predate thread.pin/unpin. */
501 readonly pinningSupported: boolean;
502 /** False on servers that predate thread title regeneration. */
503 readonly titleRegenerationSupported: boolean;
504 /** Server supports reordering this card's section. */
505 readonly reorderSupported?: boolean;
506 readonly onMoveThread?: (
507 thread: EnvironmentThreadShell,
508 direction: ThreadMoveDestination,
509 ) => void;
510 /** Position flags for the card's section so the menu disables the move that
511 would fall off the end of the list. */
512 readonly canMoveUp?: boolean;
513 readonly canMoveDown?: boolean;
514 readonly onSwipeableWillOpen: (methods: SwipeableMethods) => void;
515 readonly onSwipeableClose: (methods: SwipeableMethods) => void;
516 readonly searchMatch?: EnvironmentThreadSearchMatch;
517 readonly searchQuery?: string;
518 readonly simultaneousSwipeGesture?: ComponentProps<
519 typeof ThreadSwipeable
520 >["simultaneousWithExternalGesture"];
521}) {
522 const { width: windowWidth } = useWindowDimensions();
523 const {
524 thread,
525 variant,
526 onSelectThread,
527 onDeleteThread,
528 onRenameThread,
529 onRegenerateThreadTitle,
530 onNewThreadOnBranch,
531 onSettleThread,
532 onSnoozeThread,
533 onUnsnoozeThread,
534 onUnsettleThread,
535 onArchiveThread,
536 onPinThread,
537 onUnpinThread,
538 onMoveThread,
539 } = props;
540 const snoozedRow = props.snoozed === true;
541 const pinnedRow = props.pinned === true;
542​
543 const pr = useThreadPr(thread);
544​
545 const theme = useUniwindTheme();
546 const sidebarPane = props.pane === "sidebar";
547 const selected = props.selected === true;
548 const rowAppearance = getThreadListV2RowAppearance(theme, sidebarPane, selected);
549​
550 const status = resolveThreadListV2Status(thread);
551 const statusLabel = STATUS_LABEL_BY_STATUS[status];
552 // Settled rows label by the same stamp they sort by, so order and label
553 // can't disagree. updatedAt is always present, so the resolver never
554 // returns null here.
555 const settledTimestamp =
556 variant === "slim" && !snoozedRow ? resolveSettledThreadTimestamp(thread) : null;
557 const timeLabel =
558 settledTimestamp !== null ? relativeTime(settledTimestamp) : threadTimeLabel(thread);
559​
560 const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
561 const handleRename = useCallback(() => onRenameThread(thread), [onRenameThread, thread]);
562 const handleRegenerateTitle = useCallback(
563 () => onRegenerateThreadTitle(thread),
564 [onRegenerateThreadTitle, thread],
565 );
566 const handleSettle = useCallback(() => onSettleThread(thread), [onSettleThread, thread]);
567 const [customSnoozeOpen, setCustomSnoozeOpen] = useState(false);
568 const handleSnooze = useCallback(
569 (snoozedUntil: string) => onSnoozeThread(thread, snoozedUntil),
570 [onSnoozeThread, thread],
571 );
572 const handleUnsnooze = useCallback(() => onUnsnoozeThread(thread), [onUnsnoozeThread, thread]);
573 const handleUnsettle = useCallback(() => onUnsettleThread(thread), [onUnsettleThread, thread]);
574 const handlePin = useCallback(() => onPinThread(thread), [onPinThread, thread]);
575 const handleUnpin = useCallback(() => onUnpinThread(thread), [onUnpinThread, thread]);
576 const handleMoveUp = useCallback(() => onMoveThread?.(thread, "up"), [onMoveThread, thread]);
577 const handleMoveDown = useCallback(() => onMoveThread?.(thread, "down"), [onMoveThread, thread]);
578 const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]);
579​
580 // Swipe: the v2 primary action is the lifecycle transition. Un-settling a
581 // settled row keeps it active until new activity clears the user override.
582 const canUnsettle = variant === "slim";
583 const [snoozeGateTick, bumpSnoozeGateTick] = useState(0);
584 const snoozeGateExpiryMs = props.snoozeSupported
585 ? resolveThreadListV2SnoozeGateExpiryMs(thread, { now: new Date().toISOString() })
586 : null;
587 useEffect(() => {
588 if (snoozeGateExpiryMs === null) return;
589 const delayMs = Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647);
590 const id = setTimeout(() => bumpSnoozeGateTick((tick) => tick + 1), delayMs);
591 return () => clearTimeout(id);
592 }, [snoozeGateExpiryMs, snoozeGateTick]);
593 const swipeActions = resolveThreadListV2SwipeActions({
594 variant,
595 settlementSupported: props.settlementSupported,
596 snoozeSupported: props.snoozeSupported,
597 snoozable: canSnooze(thread, { now: new Date().toISOString() }),
598 snoozed: snoozedRow,
599 });
600 const snoozePresets = useMemo(
601 () => (swipeActions.secondary === "snooze" ? resolveSnoozePresets(new Date()) : ([] as const)),
602 [props.snoozePresetMinute, swipeActions.secondary],
603 );
604 const snoozePresetActions = useMemo<MenuAction[]>(
605 () => [
606 ...snoozePresets.map((preset) => ({
607 id: `snooze:${preset.id}`,
608 title: preset.label,
609 subtitle: preset.whenLabel,
610 })),
611 { id: "snooze:custom", title: "Custom…" },
612 ],
613 [snoozePresets],
614 );
615 // Pinned cards keep the full lifecycle menu; only the pin item flips to
616 // Unpin. (Settling a pinned thread clears the pin server-side; snoozing
617 // hides the card until wake with the pin intact.)
618 const arrangementMenuItems = useMemo<MenuAction[]>(
619 () => [
620 ...(props.reorderSupported === true
621 ? [
622 { id: "arrange", title: "Arrange threads…", image: "line.3.horizontal" },
623 {
624 id: "move-up",
625 title: "Move up",
626 image: "arrow.up",
627 attributes: { disabled: props.canMoveUp !== true },
628 } satisfies MenuAction,
629 {
630 id: "move-down",
631 title: "Move down",
632 image: "arrow.down",
633 attributes: { disabled: props.canMoveDown !== true },
634 } satisfies MenuAction,
635 ]
636 : []),
637 ...(props.pinningSupported
638 ? [
639 thread.pinnedAt != null
640 ? { id: "unpin", title: "Unpin", image: "pin.slash" }
641 : { id: "pin", title: "Pin", image: "pin" },
642 ]
643 : []),
644 ],
645 [
646 props.canMoveDown,
647 props.canMoveUp,
648 props.reorderSupported,
649 props.pinningSupported,
650 thread.pinnedAt,
651 variant,
652 ],
653 );
654 const titleMenuItems = useMemo<MenuAction[]>(
655 () => [
656 { id: "rename", title: "Rename", image: "square.and.pencil" },
657 ...buildThreadTitleRegenerationMenuItems({
658 supported: props.titleRegenerationSupported,
659 isRegenerating: thread.titleRegeneration != null,
660 }),
661 ],
662 [props.titleRegenerationSupported, thread.titleRegeneration],
663 );
664 const snoozableCardMenuActions = useMemo<MenuAction[]>(
665 () => [
666 { id: "settle", title: "Settle", image: "checkmark" },
667 {
668 id: "snooze",
669 title: "Snooze",
670 image: "clock",
671 subactions: snoozePresetActions,
672 },
673 ...arrangementMenuItems,
674 ...titleMenuItems,
675 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
676 ],
677 [arrangementMenuItems, snoozePresetActions, titleMenuItems],
678 );
679 const cardMenuActions = useMemo<MenuAction[]>(
680 () => [
681 CARD_MENU_ACTIONS[0]!,
682 ...arrangementMenuItems,
683 ...titleMenuItems,
684 ...CARD_MENU_ACTIONS.slice(1),
685 ],
686 [arrangementMenuItems, titleMenuItems],
687 );
688 const slimMenuActions = useMemo<MenuAction[]>(
689 () => [
690 SLIM_MENU_ACTIONS[0]!,
691 ...arrangementMenuItems.filter(
692 (action) => action.id !== "move-up" && action.id !== "move-down",
693 ),
694 ...titleMenuItems,
695 SLIM_MENU_ACTIONS[1]!,
696 ],
697 [arrangementMenuItems, titleMenuItems],
698 );
699 const snoozedMenuActions = useMemo<MenuAction[]>(
700 () => [SNOOZED_MENU_ACTIONS[0]!, ...titleMenuItems, SNOOZED_MENU_ACTIONS[1]!],
701 [titleMenuItems],
702 );
703 const legacyMenuActions = useMemo<MenuAction[]>(
704 () => [
705 LEGACY_MENU_ACTIONS[0]!,
706 ...arrangementMenuItems,
707 ...titleMenuItems,
708 LEGACY_MENU_ACTIONS[1]!,
709 ],
710 [arrangementMenuItems, titleMenuItems],
711 );
712 const handleMenuAction = useCallback(
713 ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
714 if (nativeEvent.event === "new-thread-on-branch") onNewThreadOnBranch(thread);
715 if (nativeEvent.event === "settle") handleSettle();
716 if (nativeEvent.event === "unsettle") handleUnsettle();
717 if (nativeEvent.event === "unsnooze") handleUnsnooze();
718 if (nativeEvent.event === "pin") handlePin();
719 if (nativeEvent.event === "unpin") handleUnpin();
720 if (nativeEvent.event === "arrange") appAtomRegistry.set(threadArrangementOpenAtom, true);
721 if (nativeEvent.event === "move-up") handleMoveUp();
722 if (nativeEvent.event === "move-down") handleMoveDown();
723 if (nativeEvent.event === "archive") handleArchive();
724 if (nativeEvent.event === "rename") handleRename();
725 if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
726 if (nativeEvent.event === "copy-thread-id") {
727 copyTextWithHaptic(thread.id, { target: "thread-id" });
728 }
729 if (nativeEvent.event === "delete") handleDelete();
730 if (nativeEvent.event === "snooze:custom") {
731 setCustomSnoozeOpen(true);
732 return;
733 }
734 const snoozeSelection = resolveThreadListV2SnoozeMenuSelection({
735 event: nativeEvent.event,
736 displayedPresets: snoozePresets,
737 now: new Date(),
738 });
739 if (snoozeSelection._tag === "selected") {
740 handleSnooze(snoozeSelection.preset.snoozedUntil);
741 } else if (snoozeSelection._tag === "expired") {
742 Alert.alert("Could not snooze thread", "That snooze time has passed. Choose another time.");
743 }
744 },
745 [
746 onNewThreadOnBranch,
747 thread,
748 handleArchive,
749 handleDelete,
750 handleRegenerateTitle,
751 handleRename,
752 handleMoveDown,
753 handleMoveUp,
754 handlePin,
755 handleSettle,
756 handleSnooze,
757 handleUnpin,
758 handleUnsettle,
759 handleUnsnooze,
760 snoozePresets,
761 ],
762 );
763 const primaryAction = useMemo(() => {
764 // Pre-settlement server: archive is the swipe action, as in v1. (Slim
765 // rows cannot occur here — unsupported environments never classify as
766 // settled.)
767 if (swipeActions.primary === "archive") {
768 return {
769 accessibilityLabel: `Archive ${thread.title}`,
770 icon: "archivebox" as const,
771 label: "Archive",
772 onPress: handleArchive,
773 };
774 }
775 if (swipeActions.primary === "unsnooze") {
776 return {
777 accessibilityLabel: `Wake ${thread.title} now`,
778 icon: "clock" as const,
779 label: "Wake",
780 onPress: handleUnsnooze,
781 };
782 }
783 return swipeActions.primary === "unsettle"
784 ? {
785 accessibilityLabel: `Un-settle ${thread.title}`,
786 icon: "arrow.uturn.backward" as const,
787 label: "Un-settle",
788 onPress: handleUnsettle,
789 }
790 : {
791 accessibilityLabel: `Settle ${thread.title}`,
792 icon: "checkmark" as const,
793 label: "Settle",
794 onPress: handleSettle,
795 };
796 }, [
797 handleArchive,
798 handleSettle,
799 handleUnsettle,
800 handleUnsnooze,
801 swipeActions.primary,
802 thread.title,
803 ]);
804 const secondaryAction = useMemo(
805 () =>
806 swipeActions.secondary === "snooze"
807 ? {
808 accessibilityLabel: `Choose when to snooze ${thread.title}`,
809 icon: "clock" as const,
810 label: "Snooze",
811 menu: {
812 actions: snoozePresetActions,
813 onPressAction: handleMenuAction,
814 title: "Snooze until",
815 },
816 onPress: () => undefined,
817 }
818 : null,
819 [handleMenuAction, snoozePresetActions, swipeActions.secondary, thread.title],
820 );
821 const swipeAccessibilityHint =
822 secondaryAction === null
823 ? `Opens the thread. Swipe left to ${primaryAction.label.toLowerCase()}.`
824 : `Opens the thread. Swipe left for ${primaryAction.label.toLowerCase()} and snooze actions.`;
825​
826 // Sidebar rows use navigation foregrounds on their active and idle surfaces.
827 const cardContent = (
828 <>
829 <View className="flex-row items-center gap-1.5">
830 {props.project ? (
831 <ProjectFavicon
832 environmentId={thread.environmentId}
833 faviconPath={props.project.faviconPath}
834 size={15}
835 projectTitle={props.projectTitle ?? props.project.title}
836 workspaceRoot={props.project.workspaceRoot}
837 />
838 ) : null}
839 <Text
840 className={cn(
841 "flex-1 text-sm font-t3-medium",
842 selected
843 ? selectedThreadRowColors.mutedForegroundClassName
844 : rowAppearance.mutedForegroundClassName,
845 )}
846 numberOfLines={1}
847 >
848 {props.projectTitle ?? props.project?.title ?? ""}
849 </Text>
850 {props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
851 {pinnedRow ? (
852 <SymbolView
853 name="pin"
854 size={11}
855 tintColorClassName={rowAppearance.mutedIconTintClassName}
856 type="monochrome"
857 />
858 ) : null}
859 <Text
860 className={cn(
861 "text-xs tabular-nums",
862 statusLabel?.className ??
863 (selected
864 ? selectedThreadRowColors.foregroundClassName
865 : rowAppearance.tertiaryForegroundClassName),
866 )}
867 >
868 {statusLabel?.label ?? timeLabel}
869 </Text>
870 </View>
871 <Text
872 className={cn(
873 "mt-1 text-base font-t3-medium",
874 selected
875 ? selectedThreadRowColors.foregroundClassName
876 : rowAppearance.foregroundClassName,
877 )}
878 numberOfLines={2}
879 >
880 {thread.title}
881 </Text>
882 {props.searchMatch ? (
883 <View className="mt-1">
884 <ThreadSearchMatchExcerpt
885 sidebar={sidebarPane}
886 match={props.searchMatch}
887 query={props.searchQuery ?? ""}
888 selected={selected}
889 />
890 </View>
891 ) : null}
892 <View className="mt-1 flex-row items-center gap-2">
893 {status === "failed" && thread.session?.lastError ? (
894 <Text
895 className={cn(
896 "flex-1 text-xs",
897 selected
898 ? selectedThreadRowColors.mutedForegroundClassName
899 : "text-danger-foreground",
900 )}
901 numberOfLines={1}
902 >
903 {thread.session.lastError}
904 </Text>
905 ) : thread.branch || props.environmentLabel ? (
906 /* "branch · machine" share one truncating line. The machine sits
907 last so a tight fit cuts the repetitive label, not the branch —
908 and machine-only fills the row for non-git projects. The glyph
909 hugs the label (it cannot live inside the Text without breaking
910 truncation), and the wrapper takes the slack so the trailers
911 stay pinned right. */
912 <View className="min-w-0 flex-1 flex-row items-center gap-1">
913 <Text
914 className={cn(
915 "shrink text-xs",
916 selected
917 ? selectedThreadRowColors.mutedForegroundClassName
918 : rowAppearance.mutedForegroundClassName,
919 )}
920 numberOfLines={1}
921 >
922 {thread.branch ? (
923 <Text
924 className={cn(
925 "text-xs",
926 selected
927 ? selectedThreadRowColors.mutedForegroundClassName
928 : rowAppearance.mutedForegroundClassName,
929 )}
930 style={{ fontFamily: MONO_FONT }}
931 >
932 {thread.branch}
933 </Text>
934 ) : null}
935 {thread.branch && props.environmentLabel ? " · " : null}
936 {props.environmentLabel ? (
937 <Text
938 className={cn(
939 "text-xs",
940 selected
941 ? selectedThreadRowColors.mutedForegroundClassName
942 : rowAppearance.tertiaryForegroundClassName,
943 )}
944 >
945 {props.environmentLabel}
946 </Text>
947 ) : null}
948 </Text>
949 {props.environmentLabel && props.environmentMachine ? (
950 <EnvironmentMachineSymbol
951 kind={props.environmentMachine}
952 size={11}
953 tintColorClassName={
954 selected
955 ? selectedThreadRowColors.mutedIconTintClassName
956 : rowAppearance.tertiaryIconTintClassName
957 }
958 />
959 ) : null}
960 </View>
961 ) : (
962 <View className="flex-1" />
963 )}
964 {pr ? (
965 <View className="flex-row items-center gap-1" accessibilityLabel={pr.accessibilityLabel}>
966 {pr.kind === "stack" || pr.others > 0 ? (
967 <SymbolView
968 name={pr.kind === "stack" ? "square.3.layers.3d" : "arrow.triangle.pull"}
969 size={12}
970 tintColorClassName={
971 pr.state === null || pr.isDraft
972 ? rowAppearance.mutedIconTintClassName
973 : pr.state === "open"
974 ? "accent-adaptive-emerald-600-400"
975 : pr.state === "closed"
976 ? "accent-adaptive-rose-600-400"
977 : "accent-adaptive-violet-600-400"
978 }
979 />
980 ) : null}
981 <Text
982 accessibilityLabel={pr.accessibilityLabel}
983 className={cn("text-xs", pr.textClassName)}
984 style={{ fontFamily: MONO_FONT }}
985 >
986 {pr.kind === "stack" || pr.others > 0 ? pr.label : `#${pr.label}`}
987 </Text>
988 </View>
989 ) : null}
990 {props.providerInstance ? (
991 <ProviderInstanceIcon
992 provider={props.providerInstance.driverKind}
993 size={14}
994 displayName={props.providerInstance.displayName}
995 accentColor={props.providerInstance.accentColor}
996 showBadge={props.providerInstance.showBadge}
997 surfaceColor={rowAppearance.providerIconSurfaceColor}
998 />
999 ) : null}
1000 </View>
1001 </>
1002 );
1003​
1004 const rowContent = (close: () => void) =>
1005 variant === "card" ? (
1006 <RowPressable
1007 key={`${thread.environmentId}:${thread.id}`}
1008 interactionClassName={rowAppearance.interactionClassName}
1009 interactionOpacity={rowAppearance.interactionOpacity}
1010 className={rowAppearance.className}
1011 accessibilityHint={swipeAccessibilityHint}
1012 accessibilityLabel={
1013 props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
1015 accessibilityRole="button"
1016 accessibilityState={{ selected }}
1017 onPress={() => {
1018 close();
1019 onSelectThread(thread);
1020 }}
1021 style={rowAppearance.cardStyle}
1023 {sidebarPane ? (
1024 cardContent
1025 ) : (
1026 /* Flat native list rows: no tonal containers — colored status
1027 labels and text hierarchy carry state, an inset hairline
1028 separates rows. The opaque screen background stays so swipe
1029 actions reveal behind the row. */
1030 <View>
1031 <View className={THREAD_LIST_V2_ROW_CONTENT_CLASS_NAME}>{cardContent}</View>
1032 {THREAD_LIST_V2_ROW_DIVIDERS && props.showTrailingDivider !== false ? (
1033 <View className="ml-5 h-px bg-border-subtle" />
1034 ) : null}
1035 </View>
1036 )}
1037 </RowPressable>
1038 ) : (
1039 <RowPressable
1040 key={`${thread.environmentId}:${thread.id}`}
1041 interactionClassName={rowAppearance.interactionClassName}
1042 interactionOpacity={rowAppearance.interactionOpacity}
1043 accessibilityHint={swipeAccessibilityHint}
1044 accessibilityLabel={
1045 props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
1047 accessibilityRole="button"
1048 accessibilityState={{ selected }}
1049 className={rowAppearance.className}
1050 onPress={() => {
1051 close();
1052 onSelectThread(thread);
1053 }}
1054 style={rowAppearance.style}
1056 {/* Settled history recedes: dimmed favicon + muted title. */}
1057 <View
1058 className={cn(
1059 "min-h-[44px] flex-row items-center gap-2.5 py-2",
1060 sidebarPane ? "px-3" : "px-5",
1061 )}
1063 {props.project ? (
1064 <View className="opacity-40">
1065 <ProjectFavicon
1066 environmentId={thread.environmentId}
1067 faviconPath={props.project.faviconPath}
1068 size={15}
1069 projectTitle={props.projectTitle ?? props.project.title}
1070 workspaceRoot={props.project.workspaceRoot}
1071 />
1072 </View>
1073 ) : null}
1074 <View className="min-w-0 flex-1">
1075 <Text
1076 className={cn(
1077 "text-base",
1078 selected
1079 ? selectedThreadRowColors.foregroundClassName
1080 : rowAppearance.mutedForegroundClassName,
1081 )}
1082 numberOfLines={1}
1084 {thread.title}
1085 </Text>
1086 {props.searchMatch ? (
1087 <ThreadSearchMatchExcerpt
1088 sidebar={sidebarPane}
1089 match={props.searchMatch}
1090 query={props.searchQuery ?? ""}
1091 selected={selected}
1092 />
1093 ) : null}
1094 </View>
1095 {props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
1096 <Text
1097 className={cn(
1098 "text-sm tabular-nums",
1099 selected
1100 ? selectedThreadRowColors.mutedForegroundClassName
1101 : snoozedRow
1102 ? rowAppearance.mutedForegroundClassName
1103 : rowAppearance.tertiaryForegroundClassName,
1104 )}
1105 style={{ fontFamily: MONO_FONT }}
1107 {snoozedRow && props.snoozeWakeLabelText !== undefined
1108 ? props.snoozeWakeLabelText
1109 : timeLabel}
1110 </Text>
1111 </View>
1112 </RowPressable>
1113 );
1114​
1115 return (
1116 <View collapsable={false}>
1117 {customSnoozeOpen && (
1118 <CustomSnoozeSheet onClose={() => setCustomSnoozeOpen(false)} onSnooze={handleSnooze} />
1119 )}
1120 <ThreadSwipeable
1121 threadKey={`${thread.environmentId}:${thread.id}`}
1122 backgroundColor={rowAppearance.swipeBackgroundColor}
1123 compactActions={variant === "slim"}
1124 containerStyle={rowAppearance.swipeContainerStyle}
1125 enableTrackpadSwipe
1126 // Full swipe commits the advertised lifecycle action (Settle /
1127 // Un-settle), never the secondary snooze action.
1128 fullSwipeAction="primary"
1129 fullSwipeWidth={props.fullSwipeWidth ?? windowWidth - 32}
1130 onDelete={handleDelete}
1131 onSwipeableClose={props.onSwipeableClose}
1132 onSwipeableWillOpen={props.onSwipeableWillOpen}
1133 primaryAction={primaryAction}
1134 secondaryAction={secondaryAction}
1135 resetKey={`${thread.environmentId}:${thread.id}:${variant}:${snoozedRow}:${thread.settledAt}:${thread.unsettledAt}:${thread.snoozedUntil}`}
1136 simultaneousWithExternalGesture={props.simultaneousSwipeGesture}
1137 threadTitle={thread.title}
1139 {(close) => (
1140 <ControlPillMenu
1141 actions={[
1142 ...(thread.branch
1143 ? [
1145 id: "new-thread-on-branch",
1146 title: getThreadListV2NewBranchMenuTitle(thread.branch),
1147 image: "square.and.pencil",
1148 },
1150 : []),
1151 { id: "copy-thread-id", title: "Copy thread ID", image: "doc.on.doc" },
1152 ...(snoozedRow
1153 ? snoozedMenuActions
1154 : !props.settlementSupported
1155 ? legacyMenuActions
1156 : canUnsettle
1157 ? slimMenuActions
1158 : swipeActions.secondary === "snooze"
1159 ? snoozableCardMenuActions
1160 : cardMenuActions),
1161 ]}
1162 onPressAction={handleMenuAction}
1163 shouldOpenOnLongPress
1165 {rowContent(close)}
1166 </ControlPillMenu>
1167 )}
1168 </ThreadSwipeable>
1169 </View>
1170 );
1171});