-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy paththread-list-v2-items.tsx
More file actions
936 lines (908 loc) · 34.9 KB
/
Copy paththread-list-v2-items.tsx
File metadata and controls
936 lines (908 loc) · 34.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
import type {
EnvironmentProject,
EnvironmentThreadShell,
} from "@t3tools/client-runtime/state/shell";
import type { EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
import type { MenuAction } from "@react-native-menu/menu";
import { memo, useCallback, useEffect, useMemo, useState, type ComponentProps } from "react";
import {
Alert,
Platform,
Pressable,
useColorScheme,
useWindowDimensions,
View,
} from "react-native";
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
import { SymbolView } from "../../components/AppSymbol";
import { AppText as Text } from "../../components/AppText";
import { ControlPillMenu } from "../../components/ControlPill";
import { ProjectFavicon } from "../../components/ProjectFavicon";
import { ProviderIcon } from "../../components/ProviderIcon";
import { cn } from "../../lib/cn";
import { relativeTime } from "../../lib/time";
import { useThemeColor } from "../../lib/useThemeColor";
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
import { useThreadPr } from "../../state/use-thread-pr";
import { ThreadSwipeable } from "../home/thread-swipe-actions";
import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
import {
resolveThreadListV2SnoozeMenuSelection,
resolveThreadListV2SnoozeGateExpiryMs,
resolveThreadListV2Status,
resolveThreadListV2SwipeActions,
type ThreadListV2Status,
} from "./threadListV2";
import { ThreadSearchMatchExcerpt } from "./thread-search-match";
/**
* Thread List v2 renders one flat native list: rich edge-to-edge rows for
* active work and a receded settled tail, all with native swipe and
* long-press actions. State reads through colored status labels and text
* hierarchy rather than card fills.
*/
const MONO_FONT = Platform.select({
ios: "Menlo",
android: "monospace",
default: "monospace",
});
// Status hues follow the system-wide convention set by sidebar v1 and the
// Live Activity/widgets (amber approval, indigo input, sky working) so a
// thread reads the same color everywhere it surfaces.
const STATUS_LABEL_BY_STATUS: Partial<
Record<ThreadListV2Status, { label: string; className: string }>
> = {
approval: { label: "Approval", className: "text-amber-700 dark:text-amber-300" },
input: { label: "Input", className: "text-indigo-600 dark:text-indigo-300" },
working: { label: "Working", className: "text-sky-600 dark:text-sky-400" },
failed: { label: "Failed", className: "text-red-700 dark:text-red-300" },
};
function threadTimeLabel(thread: EnvironmentThreadShell): string {
return relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt);
}
// Menus keep lifecycle and title regeneration together. Archive keeps its
// own surface (thread screen / settings) rather than crowding v2 rows.
const CARD_MENU_ACTIONS: MenuAction[] = [
{ id: "settle", title: "Settle", image: "checkmark" },
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
];
const SLIM_MENU_ACTIONS: MenuAction[] = [
{ id: "unsettle", title: "Un-settle", image: "arrow.uturn.backward" },
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
];
const SNOOZED_MENU_ACTIONS: MenuAction[] = [
{ id: "unsnooze", title: "Wake thread", image: "clock" },
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
];
// Pre-settlement servers: no lifecycle items, archive fills the gap.
const LEGACY_MENU_ACTIONS: MenuAction[] = [
{ id: "archive", title: "Archive", image: "archivebox" },
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
];
/** Rounded-row radius shared with the v1 sidebar rows. */
const SIDEBAR_V2_ROW_RADIUS = 12;
/** Section label + rule: the only structure in an otherwise flat list. */
export const ThreadListV2SectionDivider = memo(function ThreadListV2SectionDivider(props: {
readonly label: string;
readonly pane?: "screen" | "sidebar";
}) {
const borderColor = useThemeColor("--color-border");
return (
<View
className={cn(
"mb-1.5 mt-4 flex-row items-center gap-2.5",
props.pane === "sidebar" ? "px-3" : "px-5",
)}
>
<Text className="text-xs font-t3-medium text-foreground-tertiary">{props.label}</Text>
<View className="h-px flex-1" style={{ backgroundColor: borderColor }} />
</View>
);
});
const SNOOZE_ACCENT_LIGHT = "#2563eb";
const SNOOZE_ACCENT_DARK = "#60a5fa";
export const ThreadListV2SnoozedShelfHeader = memo(function ThreadListV2SnoozedShelfHeader(props: {
readonly count: number;
readonly expanded: boolean;
readonly onToggle: () => void;
readonly pane?: "screen" | "sidebar";
}) {
const colorScheme = useColorScheme();
return (
<Pressable
accessibilityHint={
props.expanded ? "Collapses the snoozed threads." : "Expands the snoozed threads."
}
accessibilityLabel={props.count === 1 ? "1 snoozed thread" : `${props.count} snoozed threads`}
accessibilityRole="button"
accessibilityState={{ expanded: props.expanded }}
className={cn(
"mb-1.5 mt-4 flex-row items-center gap-2.5",
props.pane === "sidebar" ? "px-3" : "px-5",
)}
onPress={props.onToggle}
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
>
<Text className="text-xs font-t3-medium text-blue-600 dark:text-blue-400">
{props.expanded ? "Snoozed" : `Snoozed (${props.count})`}
</Text>
<View className="h-px flex-1 bg-blue-500/20 dark:bg-blue-400/15" />
<SymbolView
name={props.expanded ? "chevron.up" : "chevron.down"}
size={10}
tintColor={colorScheme === "dark" ? SNOOZE_ACCENT_DARK : SNOOZE_ACCENT_LIGHT}
type="monochrome"
/>
</Pressable>
);
});
export const ThreadListV2SettledShelfHeader = memo(function ThreadListV2SettledShelfHeader(props: {
readonly count: number;
readonly expanded: boolean;
readonly onToggle: () => void;
readonly pane?: "screen" | "sidebar";
}) {
const mutedColor = useThemeColor("--color-foreground-muted");
return (
<Pressable
accessibilityHint={
props.expanded ? "Collapses the settled threads." : "Expands the settled threads."
}
accessibilityLabel={props.count === 1 ? "1 settled thread" : `${props.count} settled threads`}
accessibilityRole="button"
accessibilityState={{ expanded: props.expanded }}
className={cn(
"mb-1.5 mt-4 flex-row items-center gap-2.5",
props.pane === "sidebar" ? "px-3" : "px-5",
)}
onPress={props.onToggle}
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
>
<Text className="text-xs font-t3-medium text-foreground-tertiary">
{props.expanded ? "Settled" : `Settled (${props.count})`}
</Text>
<View className="h-px flex-1 bg-border" />
<SymbolView
name={props.expanded ? "chevron.up" : "chevron.down"}
size={10}
tintColor={mutedColor}
type="monochrome"
/>
</Pressable>
);
});
const PENDING_TASK_MENU_ACTIONS: MenuAction[] = [
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
];
/**
* A queued new task, in the same idiom as an active v2 row: it is work the
* user wrote, so it reads like the threads it will become. "Queued" takes
* the status slot — the state is the one thing that differs — and stays
* uncolored because nothing is asked of the user; the environment is simply
* not reachable yet.
*/
export const ThreadListV2PendingRow = memo(function ThreadListV2PendingRow(props: {
readonly pendingTask: PendingNewTask;
readonly project: EnvironmentProject | null;
readonly projectTitle?: string;
readonly environmentLabel: string | null;
readonly pane?: "screen" | "sidebar";
/** Draws the "Pending" divider above the first queued row. */
readonly showPendingDivider: boolean;
/** Keeps row hairlines inside a section; section headers draw their own rule. */
readonly showTrailingDivider?: boolean;
readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
}) {
const { pendingTask, onSelectPendingTask, onDeletePendingTask } = props;
const drawerColor = useThemeColor("--color-drawer");
const pressedBackgroundColor = useThemeColor("--color-subtle");
const sidebarPane = props.pane === "sidebar";
const projectTitle =
props.projectTitle ?? props.project?.title ?? pendingTask.creation.projectTitle ?? "";
const branch = pendingTask.creation.branch;
const handleMenuAction = useCallback(
({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
if (nativeEvent.event === "delete") onDeletePendingTask(pendingTask);
},
[onDeletePendingTask, pendingTask],
);
const rowContent = (
<>
<View className="flex-row items-center gap-1.5">
{props.project ? (
<ProjectFavicon
environmentId={pendingTask.message.environmentId}
faviconPath={props.project.faviconPath}
size={15}
projectTitle={projectTitle}
workspaceRoot={props.project.workspaceRoot}
/>
) : null}
<Text className="flex-1 text-sm font-t3-medium text-foreground-muted" numberOfLines={1}>
{projectTitle}
</Text>
<Text className="text-xs text-foreground-tertiary">Queued</Text>
</View>
{/* One line, unlike the two an active row allows: a queued title is
derived from the whole prompt rather than written as a title, so the
second line is usually a stray word or emoji rather than meaning. */}
<Text className="mt-1 text-base font-t3-medium text-foreground" numberOfLines={1}>
{pendingTask.title}
</Text>
{branch || props.environmentLabel ? (
<Text className="mt-1 text-xs text-foreground-muted" numberOfLines={1}>
{branch ? (
<Text className="text-xs text-foreground-muted" style={{ fontFamily: MONO_FONT }}>
{branch}
</Text>
) : null}
{branch && props.environmentLabel ? " · " : null}
{props.environmentLabel ? (
<Text className="text-xs text-foreground-tertiary">{props.environmentLabel}</Text>
) : null}
</Text>
) : null}
</>
);
return (
<>
{props.showPendingDivider ? (
<ThreadListV2SectionDivider label="Pending" pane={props.pane} />
) : null}
<ControlPillMenu
actions={PENDING_TASK_MENU_ACTIONS}
onPressAction={handleMenuAction}
shouldOpenOnLongPress
>
<Pressable
accessibilityHint="Opens the queued task for editing"
accessibilityLabel={pendingTask.title}
accessibilityRole="button"
onPress={() => onSelectPendingTask(pendingTask)}
style={
sidebarPane
? ({ pressed }) => ({
backgroundColor: pressed ? pressedBackgroundColor : drawerColor,
borderRadius: SIDEBAR_V2_ROW_RADIUS,
paddingHorizontal: 12,
paddingVertical: 10,
})
: ({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })
}
>
{sidebarPane ? (
rowContent
) : (
<View className="bg-screen">
<View className="px-5 py-2.5">{rowContent}</View>
{props.showTrailingDivider !== false ? (
<View className="ml-5 h-px bg-border-subtle" />
) : null}
</View>
)}
</Pressable>
</ControlPillMenu>
</>
);
});
export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
readonly thread: EnvironmentThreadShell;
readonly variant: "card" | "slim";
/** Snoozed-shelf row: shows its wake time and offers Wake. */
readonly snoozed?: boolean;
/** Pinned-block row: shows the pin glyph and offers Unpin. */
readonly pinned?: boolean;
/** Preformatted against the parent minute tick so this memoized row's
countdown keeps moving. */
readonly snoozeWakeLabelText?: string;
/** Parent minute tick passed as a prop so this memoized row refreshes its
native snooze menu while mounted. */
readonly snoozePresetMinute: string;
readonly project: EnvironmentProject | null;
readonly projectTitle?: string;
readonly providerDriver: string | null;
/** Which machine hosts the thread. Null when only one environment is
connected — repeating the same label on every row is noise. Mirrors
the web sidebar's remote-environment cloud icon, but as text since
phones have no hover tooltips. */
readonly environmentLabel: string | null;
/** Hosting surface. "screen" (default) renders the compact Home idiom:
flat edge-to-edge rows on the screen background with inset hairlines.
"sidebar" renders the iPad split-view idiom: rounded rows blending
into the drawer surface, selection filled with the accent color —
matching the v1 sidebar rows. */
readonly pane?: "screen" | "sidebar";
/** Keeps row hairlines inside a section; section headers draw their own rule. */
readonly showTrailingDivider?: boolean;
/** Highlights the thread open in the detail pane (iPad split view). The
compact Home list never sets it — phones navigate away on select. */
readonly selected?: boolean;
/** Override for narrow panes (iPad sidebar); defaults to window width. */
readonly fullSwipeWidth?: number;
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => void;
readonly onSettleThread: (thread: EnvironmentThreadShell) => void;
readonly onSnoozeThread: (thread: EnvironmentThreadShell, snoozedUntil: string) => void;
readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => void;
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
readonly onPinThread: (thread: EnvironmentThreadShell) => void;
readonly onUnpinThread: (thread: EnvironmentThreadShell) => void;
/** False on environments whose server predates thread.settle/unsettle:
swipe + menu fall back to Archive instead of failing on use. */
readonly settlementSupported: boolean;
/** False on servers that predate thread.snooze/unsnooze. */
readonly snoozeSupported: boolean;
/** False on servers that predate thread.pin/unpin. */
readonly pinningSupported: boolean;
/** False on servers that predate thread title regeneration. */
readonly titleRegenerationSupported: boolean;
/** False on servers that predate thread.pin.reorder. Gates the pinned
Move up / Move down menu items. */
readonly pinReorderSupported?: boolean;
readonly onMovePinnedThread?: (thread: EnvironmentThreadShell, direction: "up" | "down") => void;
/** Position flags for the pinned block so the menu disables the move that
would fall off the end of the list. */
readonly canMovePinnedUp?: boolean;
readonly canMovePinnedDown?: boolean;
readonly onSwipeableWillOpen: (methods: SwipeableMethods) => void;
readonly onSwipeableClose: (methods: SwipeableMethods) => void;
readonly projectCwd?: string | null;
readonly searchMatch?: EnvironmentThreadSearchMatch;
readonly searchQuery?: string;
readonly simultaneousSwipeGesture?: ComponentProps<
typeof ThreadSwipeable
>["simultaneousWithExternalGesture"];
}) {
const { width: windowWidth } = useWindowDimensions();
const {
thread,
variant,
onSelectThread,
onDeleteThread,
onRegenerateThreadTitle,
onSettleThread,
onSnoozeThread,
onUnsnoozeThread,
onUnsettleThread,
onArchiveThread,
onPinThread,
onUnpinThread,
onMovePinnedThread,
} = props;
const snoozedRow = props.snoozed === true;
const pinnedRow = props.pinned === true;
const pr = useThreadPr(thread, props.projectCwd ?? props.project?.workspaceRoot ?? null);
const screenColor = useThemeColor("--color-screen");
const drawerColor = useThemeColor("--color-drawer");
const pressedBackgroundColor = useThemeColor("--color-subtle");
const selectedBackgroundColor = useThemeColor("--color-user-bubble");
const pinTintColor = useThemeColor("--color-foreground-muted");
const sidebarPane = props.pane === "sidebar";
const selected = props.selected === true;
const status = resolveThreadListV2Status(thread);
const statusLabel = STATUS_LABEL_BY_STATUS[status];
const timeLabel = threadTimeLabel(thread);
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
const handleRegenerateTitle = useCallback(
() => onRegenerateThreadTitle(thread),
[onRegenerateThreadTitle, thread],
);
const handleSettle = useCallback(() => onSettleThread(thread), [onSettleThread, thread]);
const handleSnooze = useCallback(
(snoozedUntil: string) => onSnoozeThread(thread, snoozedUntil),
[onSnoozeThread, thread],
);
const handleUnsnooze = useCallback(() => onUnsnoozeThread(thread), [onUnsnoozeThread, thread]);
const handleUnsettle = useCallback(() => onUnsettleThread(thread), [onUnsettleThread, thread]);
const handlePin = useCallback(() => onPinThread(thread), [onPinThread, thread]);
const handleUnpin = useCallback(() => onUnpinThread(thread), [onUnpinThread, thread]);
const handleMovePinnedUp = useCallback(
() => onMovePinnedThread?.(thread, "up"),
[onMovePinnedThread, thread],
);
const handleMovePinnedDown = useCallback(
() => onMovePinnedThread?.(thread, "down"),
[onMovePinnedThread, thread],
);
const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]);
// Swipe: the v2 primary action is the lifecycle transition. Every settled
// row can un-settle — explicit settles clear the override, auto-settled
// rows get pinned active until real activity clears the pin.
const canUnsettle = variant === "slim";
const [snoozeGateTick, bumpSnoozeGateTick] = useState(0);
const snoozeGateExpiryMs = props.snoozeSupported
? resolveThreadListV2SnoozeGateExpiryMs(thread, { now: new Date().toISOString() })
: null;
useEffect(() => {
if (snoozeGateExpiryMs === null) return;
const delayMs = Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647);
const id = setTimeout(() => bumpSnoozeGateTick((tick) => tick + 1), delayMs);
return () => clearTimeout(id);
}, [snoozeGateExpiryMs, snoozeGateTick]);
const swipeActions = resolveThreadListV2SwipeActions({
variant,
settlementSupported: props.settlementSupported,
snoozeSupported: props.snoozeSupported,
snoozable: canSnooze(thread, { now: new Date().toISOString() }),
snoozed: snoozedRow,
});
const snoozePresets = useMemo(
() => (swipeActions.secondary === "snooze" ? resolveSnoozePresets(new Date()) : ([] as const)),
[props.snoozePresetMinute, swipeActions.secondary],
);
const snoozePresetActions = useMemo<MenuAction[]>(
() =>
snoozePresets.map((preset) => ({
id: `snooze:${preset.id}`,
title: preset.label,
subtitle: preset.whenLabel,
})),
[snoozePresets],
);
// Pinned cards keep the full lifecycle menu; only the pin item flips to
// Unpin. (Settling a pinned thread clears the pin server-side; snoozing
// hides the card until wake with the pin intact.)
const pinMenuItem = useMemo<MenuAction[]>(
() =>
props.pinningSupported
? [
...(pinnedRow && props.pinReorderSupported === true
? [
{
id: "move-pin-up",
title: "Move up",
image: "arrow.up",
attributes: { disabled: props.canMovePinnedUp !== true },
} satisfies MenuAction,
{
id: "move-pin-down",
title: "Move down",
image: "arrow.down",
attributes: { disabled: props.canMovePinnedDown !== true },
} satisfies MenuAction,
]
: []),
pinnedRow
? { id: "unpin", title: "Unpin", image: "pin.slash" }
: { id: "pin", title: "Pin", image: "pin" },
]
: [],
[
pinnedRow,
props.canMovePinnedDown,
props.canMovePinnedUp,
props.pinReorderSupported,
props.pinningSupported,
],
);
const titleRegenerationMenuItems = useMemo<MenuAction[]>(
() =>
buildThreadTitleRegenerationMenuItems({
supported: props.titleRegenerationSupported,
isRegenerating: thread.titleRegeneration != null,
}),
[props.titleRegenerationSupported, thread.titleRegeneration],
);
const snoozableCardMenuActions = useMemo<MenuAction[]>(
() => [
{ id: "settle", title: "Settle", image: "checkmark" },
{
id: "snooze",
title: "Snooze",
image: "clock",
subactions: snoozePresetActions,
},
...pinMenuItem,
...titleRegenerationMenuItems,
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
],
[pinMenuItem, snoozePresetActions, titleRegenerationMenuItems],
);
const cardMenuActions = useMemo<MenuAction[]>(
() => [
CARD_MENU_ACTIONS[0]!,
...pinMenuItem,
...titleRegenerationMenuItems,
...CARD_MENU_ACTIONS.slice(1),
],
[pinMenuItem, titleRegenerationMenuItems],
);
const slimMenuActions = useMemo<MenuAction[]>(
() => [SLIM_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, SLIM_MENU_ACTIONS[1]!],
[titleRegenerationMenuItems],
);
const snoozedMenuActions = useMemo<MenuAction[]>(
() => [SNOOZED_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, SNOOZED_MENU_ACTIONS[1]!],
[titleRegenerationMenuItems],
);
const legacyMenuActions = useMemo<MenuAction[]>(
() => [LEGACY_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, LEGACY_MENU_ACTIONS[1]!],
[titleRegenerationMenuItems],
);
const handleMenuAction = useCallback(
({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
if (nativeEvent.event === "settle") handleSettle();
if (nativeEvent.event === "unsettle") handleUnsettle();
if (nativeEvent.event === "unsnooze") handleUnsnooze();
if (nativeEvent.event === "pin") handlePin();
if (nativeEvent.event === "unpin") handleUnpin();
if (nativeEvent.event === "move-pin-up") handleMovePinnedUp();
if (nativeEvent.event === "move-pin-down") handleMovePinnedDown();
if (nativeEvent.event === "archive") handleArchive();
if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
if (nativeEvent.event === "delete") handleDelete();
const snoozeSelection = resolveThreadListV2SnoozeMenuSelection({
event: nativeEvent.event,
displayedPresets: snoozePresets,
now: new Date(),
});
if (snoozeSelection._tag === "selected") {
handleSnooze(snoozeSelection.preset.snoozedUntil);
} else if (snoozeSelection._tag === "expired") {
Alert.alert("Could not snooze thread", "That snooze time has passed. Choose another time.");
}
},
[
handleArchive,
handleDelete,
handleRegenerateTitle,
handleMovePinnedDown,
handleMovePinnedUp,
handlePin,
handleSettle,
handleSnooze,
handleUnpin,
handleUnsettle,
handleUnsnooze,
snoozePresets,
],
);
const primaryAction = useMemo(() => {
// Pre-settlement server: archive is the swipe action, as in v1. (Slim
// rows cannot occur here — unsupported environments never classify as
// settled.)
if (swipeActions.primary === "archive") {
return {
accessibilityLabel: `Archive ${thread.title}`,
icon: "archivebox" as const,
label: "Archive",
onPress: handleArchive,
};
}
if (swipeActions.primary === "unsnooze") {
return {
accessibilityLabel: `Wake ${thread.title} now`,
icon: "clock" as const,
label: "Wake",
onPress: handleUnsnooze,
};
}
return swipeActions.primary === "unsettle"
? {
accessibilityLabel: `Un-settle ${thread.title}`,
icon: "arrow.uturn.backward" as const,
label: "Un-settle",
onPress: handleUnsettle,
}
: {
accessibilityLabel: `Settle ${thread.title}`,
icon: "checkmark" as const,
label: "Settle",
onPress: handleSettle,
};
}, [
handleArchive,
handleSettle,
handleUnsettle,
handleUnsnooze,
swipeActions.primary,
thread.title,
]);
const secondaryAction = useMemo(
() =>
swipeActions.secondary === "snooze"
? {
accessibilityLabel: `Choose when to snooze ${thread.title}`,
icon: "clock" as const,
label: "Snooze",
menu: {
actions: snoozePresetActions,
onPressAction: handleMenuAction,
title: "Snooze until",
},
onPress: () => undefined,
}
: null,
[handleMenuAction, snoozePresetActions, swipeActions.secondary, thread.title],
);
const swipeAccessibilityHint =
secondaryAction === null
? `Opens the thread. Swipe left to ${primaryAction.label.toLowerCase()}.`
: `Opens the thread. Swipe left for ${primaryAction.label.toLowerCase()} and snooze actions.`;
// The sidebar pane fills selected rows with the accent color (matching the
// v1 sidebar), so every piece of row text needs a white-on-accent variant.
const cardContent = (
<>
<View className="flex-row items-center gap-1.5">
{props.project ? (
<ProjectFavicon
environmentId={thread.environmentId}
faviconPath={props.project.faviconPath}
size={15}
projectTitle={props.projectTitle ?? props.project.title}
workspaceRoot={props.project.workspaceRoot}
/>
) : null}
<Text
className={cn(
"flex-1 text-sm font-t3-medium",
selected ? "text-user-bubble-foreground-muted" : "text-foreground-muted",
)}
numberOfLines={1}
>
{props.projectTitle ?? props.project?.title ?? ""}
</Text>
{pinnedRow ? (
<SymbolView name="pin" size={11} tintColor={pinTintColor} type="monochrome" />
) : null}
<Text
className={cn(
"text-xs tabular-nums",
selected ? "text-white" : (statusLabel?.className ?? "text-foreground-tertiary"),
)}
>
{statusLabel?.label ?? timeLabel}
</Text>
</View>
<Text
className={cn(
"mt-1 text-base font-t3-medium",
selected ? "text-user-bubble-foreground" : "text-foreground",
)}
numberOfLines={2}
>
{thread.title}
</Text>
{props.searchMatch ? (
<View className="mt-1">
<ThreadSearchMatchExcerpt
match={props.searchMatch}
query={props.searchQuery ?? ""}
selected={selected}
/>
</View>
) : null}
<View className="mt-1 flex-row items-center gap-2">
{status === "failed" && thread.session?.lastError ? (
<Text
className={cn(
"flex-1 text-xs",
selected
? "text-user-bubble-foreground-muted"
: "text-red-600/80 dark:text-red-400/80",
)}
numberOfLines={1}
>
{thread.session.lastError}
</Text>
) : thread.branch || props.environmentLabel ? (
/* "branch · machine" share one truncating line. The machine sits
last so a tight fit cuts the repetitive label, not the branch —
and machine-only fills the row for non-git projects. */
<Text
className={cn(
"flex-1 text-xs",
selected ? "text-user-bubble-foreground-muted" : "text-foreground-muted",
)}
numberOfLines={1}
>
{thread.branch ? (
<Text
className={cn(
"text-xs",
selected ? "text-user-bubble-foreground-muted" : "text-foreground-muted",
)}
style={{ fontFamily: MONO_FONT }}
>
{thread.branch}
</Text>
) : null}
{thread.branch && props.environmentLabel ? " · " : null}
{props.environmentLabel ? (
<Text
className={cn(
"text-xs",
selected ? "text-user-bubble-foreground-muted" : "text-foreground-tertiary",
)}
>
{props.environmentLabel}
</Text>
) : null}
</Text>
) : (
<View className="flex-1" />
)}
{pr ? (
<Text
accessibilityLabel={pr.accessibilityLabel}
className={cn("text-xs", selected ? "text-white" : pr.textClassName)}
style={{ fontFamily: MONO_FONT }}
>
#{pr.label}
</Text>
) : null}
{props.providerDriver ? (
<View className="opacity-60">
<ProviderIcon provider={props.providerDriver} size={14} />
</View>
) : null}
</View>
</>
);
const rowContent = (close: () => void) =>
variant === "card" ? (
<Pressable
accessibilityHint={swipeAccessibilityHint}
accessibilityLabel={thread.title}
accessibilityRole="button"
accessibilityState={{ selected }}
onPress={() => {
close();
onSelectThread(thread);
}}
style={
sidebarPane
? ({ pressed }) => ({
backgroundColor: selected
? selectedBackgroundColor
: pressed
? pressedBackgroundColor
: drawerColor,
borderRadius: SIDEBAR_V2_ROW_RADIUS,
paddingHorizontal: 12,
paddingVertical: 10,
})
: ({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })
}
>
{sidebarPane ? (
cardContent
) : (
/* Flat native list rows: no tonal containers — colored status
labels and text hierarchy carry state, an inset hairline
separates rows. The opaque screen background stays so swipe
actions reveal behind the row. */
<View className="bg-screen">
<View className="px-5 py-2.5">{cardContent}</View>
{props.showTrailingDivider !== false ? (
<View className="ml-5 h-px bg-border-subtle" />
) : null}
</View>
)}
</Pressable>
) : (
<Pressable
accessibilityHint={swipeAccessibilityHint}
accessibilityLabel={thread.title}
accessibilityRole="button"
accessibilityState={{ selected }}
className={sidebarPane ? undefined : "bg-screen"}
onPress={() => {
close();
onSelectThread(thread);
}}
style={
sidebarPane
? ({ pressed }) => ({
backgroundColor: selected
? selectedBackgroundColor
: pressed
? pressedBackgroundColor
: drawerColor,
borderRadius: SIDEBAR_V2_ROW_RADIUS,
})
: ({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })
}
>
{/* Settled history recedes: dimmed favicon + muted title. */}
<View
className={cn(
"min-h-[44px] flex-row items-center gap-2.5 py-2",
sidebarPane ? "px-3" : "px-5",
)}
>
{props.project ? (
<View className="opacity-40">
<ProjectFavicon
environmentId={thread.environmentId}
faviconPath={props.project.faviconPath}
size={15}
projectTitle={props.projectTitle ?? props.project.title}
workspaceRoot={props.project.workspaceRoot}
/>
</View>
) : null}
<View className="min-w-0 flex-1">
<Text
className={cn(
"text-base",
selected ? "text-user-bubble-foreground" : "text-foreground-muted",
)}
numberOfLines={1}
>
{thread.title}
</Text>
{props.searchMatch ? (
<ThreadSearchMatchExcerpt
match={props.searchMatch}
query={props.searchQuery ?? ""}
selected={selected}
/>
) : null}
</View>
<Text
className={cn(
"text-sm tabular-nums",
selected
? "text-user-bubble-foreground-muted"
: snoozedRow
? "text-blue-600 dark:text-blue-400"
: "text-foreground-tertiary",
)}
style={{ fontFamily: MONO_FONT }}
>
{snoozedRow && props.snoozeWakeLabelText !== undefined
? props.snoozeWakeLabelText
: relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt)}
</Text>
</View>
</Pressable>
);
return (
<>
<ThreadSwipeable
backgroundColor={sidebarPane ? drawerColor : screenColor}
compactActions={variant === "slim"}
containerStyle={
sidebarPane ? { borderRadius: SIDEBAR_V2_ROW_RADIUS, overflow: "hidden" } : undefined
}
enableTrackpadSwipe
// Full swipe commits the advertised lifecycle action (Settle /
// Un-settle), never the secondary snooze action.
fullSwipeAction="primary"
fullSwipeWidth={props.fullSwipeWidth ?? windowWidth - 32}
onDelete={handleDelete}
onSwipeableClose={props.onSwipeableClose}
onSwipeableWillOpen={props.onSwipeableWillOpen}
primaryAction={primaryAction}
secondaryAction={secondaryAction}
resetKey={`${thread.environmentId}:${thread.id}`}
simultaneousWithExternalGesture={props.simultaneousSwipeGesture}
threadTitle={thread.title}
>
{(close) => (
<ControlPillMenu
actions={
snoozedRow
? snoozedMenuActions
: !props.settlementSupported
? legacyMenuActions
: canUnsettle
? slimMenuActions
: swipeActions.secondary === "snooze"
? snoozableCardMenuActions
: cardMenuActions
}
onPressAction={handleMenuAction}
shouldOpenOnLongPress
>
{rowContent(close)}
</ControlPillMenu>
)}
</ThreadSwipeable>
</>
);
});