Open History to see the last commit
1import type {
2 EnvironmentProject,
3 EnvironmentThreadShell,
4} from "@t3tools/client-runtime/state/shell";
5import type { EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
6import type { EnvironmentMachineKind } from "@t3tools/contracts";
7import type { MenuAction } from "@react-native-menu/menu";
8import { SymbolView } from "../../components/AppSymbol";
9import { memo, useCallback, useMemo, type ComponentProps } from "react";
10import { Platform, Pressable, useWindowDimensions, View } from "react-native";
11import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
12import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
13import Svg, { Circle, Path } from "react-native-svg";
14
15import { RowPressable } from "../../components/RowPressable";
16import { AppText as Text } from "../../components/AppText";
17import { ControlPillMenu } from "../../components/ControlPill";
18import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
19import { ProjectFavicon } from "../../components/ProjectFavicon";
20import { cn } from "../../lib/cn";
21import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
22import { HOME_HORIZONTAL_INSET } from "../../lib/layoutMetrics";
23import { relativeTime } from "../../lib/time";
24import { useUniwindTheme } from "../../lib/useUniwindTheme";
25import type { PendingNewTask } from "../../state/use-pending-new-tasks";
26import { useThreadPr, type ThreadPrPresentation } from "../../state/use-thread-pr";
27import type { HomeGroupDisplayAction } from "../home/homeListItems";
28import { ThreadSwipeable } from "../home/thread-swipe-actions";
29import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
30import { QueuedMessageIcon } from "./queued-message-icon";
31import { resolveThreadStatus } from "./threadPresentation";
32import { ThreadSearchMatchExcerpt } from "./thread-search-match";
33
34/**
35 * Shared presentation for the thread lists: the compact (phone) Home list and
36 * the iPad sidebar render the SAME items — group headers with collapse,
37 * thread rows with status/PR/subtitle, and show-more rows — differing only in
38 * metrics and chrome via `variant`.
39 */
40export type ThreadListVariant = "compact" | "sidebar";
41
42/** Left inset that aligns compact secondary rows with the title column. */
43export const THREAD_LIST_COMPACT_INSET = HOME_HORIZONTAL_INSET;
44const SIDEBAR_ROW_RADIUS = 12;
45
46function pullRequestTintColor(
47 pr: Pick<ThreadPrPresentation, "state" | "isDraft" | "others" | "kind">,
48 colorScheme: "light" | "dark",
49) {
50 const dark = colorScheme === "dark";
51 if (pr.state === "open" && pr.isDraft === true) {
52 return dark ? "#a1a1aa" : "#71717a";
53 }
54 switch (pr.state) {
55 case "open":
56 return dark ? "#34d399" : "#059669";
57 case "merged":
58 return dark ? "#a78bfa" : "#7c3aed";
59 case "closed":
60 if (pr.kind === "stack" || pr.others > 0) {
61 return dark ? "#fb7185" : "#e11d48";
62 }
63 return dark ? "#a1a1aa" : "#71717a";
64 case null:
65 return dark ? "#a1a1aa" : "#71717a";
66 }
67}
68
69function PullRequestIcon(props: { readonly size: number; readonly color: string }) {
70 return (
71 <Svg
72 width={props.size}
73 height={props.size}
74 viewBox="0 0 24 24"
75 fill="none"
76 stroke={props.color}
77 strokeWidth={2}
78 strokeLinecap="round"
79 strokeLinejoin="round"
80 >
81 <Circle cx={18} cy={18} r={3} />
82 <Circle cx={6} cy={6} r={3} />
83 <Path d="M13 6h3a2 2 0 0 1 2 2v7" />
84 <Path d="M6 9v12" />
85 </Svg>
86 );
87}
88
89/* ─── Project group header ───────────────────────────────────────────── */
90
91export const ThreadListGroupHeader = memo(function ThreadListGroupHeader(props: {
92 readonly variant: ThreadListVariant;
93 readonly project: EnvironmentProject;
94 readonly title: string;
95 readonly threadCount: number;
96 readonly collapsed: boolean;
97 readonly isFirst: boolean;
98 readonly groupKey: string;
99 readonly onGroupAction: (key: string, action: HomeGroupDisplayAction) => void;
100 /** Project a quick new thread should target; null hides the button. */
101 readonly newThreadTarget?: EnvironmentProject | null;
102 readonly onNewThread?: (project: EnvironmentProject) => void;
103}) {
104 const { groupKey, onGroupAction, onNewThread } = props;
105 const newThreadTarget = props.newThreadTarget ?? null;
106 const compact = props.variant === "compact";
107 const handleToggle = useCallback(
108 () => onGroupAction(groupKey, "toggle-collapsed"),
109 [groupKey, onGroupAction],
110 );
111 const handleNewThread = useCallback(() => {
112 if (newThreadTarget) {
113 onNewThread?.(newThreadTarget);
114 }
115 }, [newThreadTarget, onNewThread]);
116 const showNewThreadButton = onNewThread !== undefined && newThreadTarget !== null;
117
118 // The new-thread button is a SIBLING of the collapse toggle, not a child:
119 // nested touchables are unreachable to VoiceOver/TalkBack (the parent
120 // swallows focus). Row padding lives on the container (explicit styles —
121 // dynamic padding classes on Pressable did not apply reliably) so both
122 // children share one centerline; hitSlop restores the padded tap area.
123 const verticalHitSlop = { top: props.isFirst ? 8 : 24, bottom: 12 };
124 return (
125 <View
126 className={compact ? "flex-row items-center bg-screen" : "flex-row items-center"}
127 style={{
128 minHeight: compact ? 44 : 36,
129 paddingLeft: compact ? 20 : 12,
130 // Compact right padding centers the 20pt plus glyph on the thread
131 // rows' trailing chevron column (18 + 13/2 ≈ 24.5 from the edge).
132 paddingRight: compact ? 14 : 12,
133 paddingBottom: compact ? 12 : 8,
134 paddingTop: props.isFirst ? (compact ? 8 : 4) : compact ? 24 : 20,
135 }}
136 >
137 <Pressable
138 accessibilityRole="button"
139 accessibilityState={{ expanded: !props.collapsed }}
140 accessibilityLabel={`${props.title}, ${props.threadCount} threads`}
141 accessibilityHint={props.collapsed ? "Expands the project" : "Collapses the project"}
142 className={
143 compact ? "flex-1 flex-row items-center gap-2.5" : "flex-1 flex-row items-center gap-2"
144 }
145 hitSlop={{ ...verticalHitSlop, left: compact ? 20 : 12 }}
146 onPress={handleToggle}
147 >
148 <ProjectFavicon
149 environmentId={props.project.environmentId}
150 faviconPath={props.project.faviconPath}
151 open={!props.collapsed}
152 size={compact ? 22 : 18}
153 projectTitle={props.project.title}
154 workspaceRoot={props.project.workspaceRoot}
155 />
156 <Text
157 className={
158 compact
159 ? "flex-shrink text-base font-t3-bold tracking-[0.2px] text-foreground-muted"
160 : "flex-shrink text-sm font-t3-bold tracking-[0.2px] text-drawer-foreground-muted"
161 }
162 numberOfLines={1}
163 >
164 {props.title}
165 </Text>
166 <Text
167 className={
168 compact
169 ? "flex-1 text-sm font-t3-medium text-foreground-tertiary"
170 : "flex-1 text-xs font-t3-medium text-drawer-foreground-muted"
171 }
172 >
173 {props.threadCount}
174 </Text>
175 </Pressable>
176 {showNewThreadButton ? (
177 <Pressable
178 accessibilityLabel={`Create new thread in ${props.title}`}
179 accessibilityRole="button"
180 hitSlop={{ ...verticalHitSlop, left: 10, right: 14 }}
181 onPress={handleNewThread}
182 style={({ pressed }) => ({ opacity: pressed ? 0.5 : 1, paddingLeft: 12 })}
183 >
184 <SymbolView
185 name="plus"
186 size={compact ? 20 : 16}
187 tintColorClassName="accent-icon-muted"
188 type="monochrome"
189 weight="medium"
190 />
191 </Pressable>
192 ) : null}
193 </View>
194 );
195});
196
197/* ─── Show more / show less row ──────────────────────────────────────── */
198
199export const ThreadListShowMoreRow = memo(function ThreadListShowMoreRow(props: {
200 readonly variant: ThreadListVariant;
201 readonly hiddenCount: number;
202 readonly canShowLess: boolean;
203 readonly groupKey: string;
204 readonly onGroupAction: (key: string, action: HomeGroupDisplayAction) => void;
205}) {
206 const showsMore = props.hiddenCount > 0;
207 const compact = props.variant === "compact";
208 const { groupKey, onGroupAction } = props;
209 const handleShowMore = useCallback(
210 () => onGroupAction(groupKey, "show-more"),
211 [groupKey, onGroupAction],
212 );
213 const handleShowLess = useCallback(
214 () => onGroupAction(groupKey, "show-less"),
215 [groupKey, onGroupAction],
216 );
217
218 const button = (label: string, icon: "chevron.down" | "chevron.up", onPress: () => void) => (
219 <Pressable
220 accessibilityRole="button"
221 accessibilityLabel={label === "Show more" ? "Show more threads" : "Show fewer threads"}
222 className="rounded-full bg-subtle"
223 hitSlop={6}
224 onPress={onPress}
225 style={({ pressed }) => ({
226 opacity: pressed ? 0.6 : 1,
227 paddingHorizontal: compact ? 14 : 12,
228 paddingVertical: compact ? 7 : 6,
229 borderCurve: "continuous",
230 })}
231 >
232 <View className="flex-row items-center gap-1.5">
233 <SymbolView
234 name={icon}
235 size={10}
236 tintColorClassName="accent-icon-subtle"
237 type="monochrome"
238 weight="semibold"
239 />
240 <Text
241 className={
242 compact
243 ? "text-sm font-t3-medium text-foreground-muted"
244 : "text-xs font-t3-medium text-drawer-foreground-muted"
245 }
246 >
247 {label}
248 </Text>
249 </View>
250 </Pressable>
251 );
252
253 return (
254 <View
255 className={
256 compact ? "flex-row items-center gap-2.5 bg-screen" : "flex-row items-center gap-2"
257 }
258 style={{
259 paddingLeft: compact ? THREAD_LIST_COMPACT_INSET : 12,
260 paddingRight: compact ? 18 : 12,
261 paddingVertical: compact ? 12 : 8,
262 }}
263 >
264 {showsMore ? button("Show more", "chevron.down", handleShowMore) : null}
265 {props.canShowLess ? button("Show less", "chevron.up", handleShowLess) : null}
266 </View>
267 );
268});
269
270/* ─── Pending task row ───────────────────────────────────────────────── */
271
272const PENDING_TASK_MENU_ACTIONS: MenuAction[] = [
273 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
274];
275
276const DRAFT_TASK_MENU_ACTIONS: MenuAction[] = [
277 { id: "delete", title: "Discard", image: "trash", attributes: { destructive: true } },
278];
279
280/**
281 * Unsent work: a task queued in the outbox for its environment to reconnect,
282 * or a draft still sitting in the project's new-task composer. Tapping
283 * reopens the composer with everything prefilled; the row disappears once
284 * the work is sent and the real thread arrives. The two kinds differ in what
285 * happens next, so the pill and icon say which one this is: a queued task
286 * sends itself, a draft waits for the user.
287 */
288export const PendingTaskListRow = memo(function PendingTaskListRow(props: {
289 readonly variant: ThreadListVariant;
290 readonly pendingTask: PendingNewTask;
291 readonly environmentLabel: string | null;
292 readonly environmentMachine?: EnvironmentMachineKind;
293 readonly isLast: boolean;
294 readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
295 readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
296}) {
297 const compact = props.variant === "compact";
298
299 const { pendingTask, onSelectPendingTask, onDeletePendingTask } = props;
300 const isDraft = pendingTask.kind === "draft";
301 const timestamp = isDraft ? null : relativeTime(pendingTask.createdAt);
302 // The pill only has room for one word, so what happens next goes in the
303 // subtitle: a queued task sends itself, a draft waits for the user.
304 const subtitleParts = [
305 isDraft ? null : "Sends on reconnect",
306 props.environmentLabel,
307 pendingTask.branch,
308 ].filter((part): part is string => Boolean(part));
309
310 const handleMenuAction = useCallback(
311 ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
312 if (nativeEvent.event === "delete") onDeletePendingTask(pendingTask);
313 },
314 [onDeletePendingTask, pendingTask],
315 );
316
317 const statusPill = isDraft ? (
318 <View className="rounded-full bg-adaptive-amber-500-a12-a16 px-1.5 py-0.5">
319 <Text className="text-3xs font-t3-bold text-adaptive-amber-700-300">Draft</Text>
320 </View>
321 ) : (
322 <View className="rounded-full bg-subtle px-1.5 py-0.5">
323 <Text
324 className={cn(
325 "text-3xs font-t3-bold text-foreground-muted",
326 !compact && "text-drawer-foreground-muted",
327 )}
328 >
329 Pending
330 </Text>
331 </View>
332 );
333
334 const subtitleRow =
335 subtitleParts.length > 0 ? (
336 <View className="mt-px flex-row items-center gap-1.5">
337 <SymbolView
338 name={isDraft ? "square.and.pencil" : "tray.and.arrow.up"}
339 size={10}
340 tintColorClassName={compact ? "accent-icon-subtle" : "accent-drawer-foreground-muted"}
341 type="monochrome"
342 />
343 {props.environmentLabel && props.environmentMachine ? (
344 <EnvironmentMachineSymbol
345 kind={props.environmentMachine}
346 size={compact ? 12 : 10}
347 tintColorClassName={compact ? "accent-icon-subtle" : "accent-drawer-foreground-muted"}
348 />
349 ) : null}
350 <Text
351 className={
352 compact
353 ? "shrink text-sm text-foreground-muted"
354 : "shrink text-xs text-drawer-foreground-muted"
355 }
356 numberOfLines={1}
357 >
358 {subtitleParts.join(" · ")}
359 </Text>
360 </View>
361 ) : null;
362
363 const accessibilityHint = isDraft
364 ? "Opens the draft in the new task composer"
365 : "Sends when the environment reconnects. Opens the task for editing";
366
367 const rowContent = compact ? (
368 <RowPressable
369 key={pendingTask.key}
370 accessibilityHint={accessibilityHint}
371 accessibilityLabel={pendingTask.title}
372 accessibilityRole="button"
373 className="bg-screen"
374 onPress={() => onSelectPendingTask(pendingTask)}
375 >
376 <View className="pr-[18px] pt-[10px]" style={{ paddingLeft: THREAD_LIST_COMPACT_INSET }}>
377 <View className={cn("gap-[3px] pb-[10px]", !props.isLast && "border-b border-separator")}>
378 <View className="flex-row items-center justify-between gap-2">
379 <Text
380 className={cn(
381 "flex-1 text-lg font-t3-bold text-foreground",
382 !compact && "text-drawer-foreground",
383 )}
384 numberOfLines={1}
385 >
386 {pendingTask.title}
387 </Text>
388 <View className="flex-row items-center gap-2">
389 {statusPill}
390 {timestamp !== null ? (
391 <Text
392 className={cn(
393 "text-base tabular-nums text-foreground-tertiary",
394 !compact && "text-drawer-foreground-muted",
395 )}
396 >
397 {timestamp}
398 </Text>
399 ) : null}
400 <SymbolView
401 name="chevron.right"
402 size={13}
403 tintColorClassName="accent-icon-subtle"
404 type="monochrome"
405 />
406 </View>
407 </View>
408 {subtitleRow}
409 </View>
410 </View>
411 </RowPressable>
412 ) : (
413 <RowPressable
414 key={pendingTask.key}
415 accessibilityHint={accessibilityHint}
416 accessibilityLabel={pendingTask.title}
417 accessibilityRole="button"
418 interactionClassName="bg-thread-hover"
419 onPress={() => onSelectPendingTask(pendingTask)}
420 style={{
421 borderRadius: SIDEBAR_ROW_RADIUS,
422 minHeight: 64,
423 justifyContent: "center",
424 paddingHorizontal: 12,
425 paddingVertical: 10,
426 }}
427 >
428 <View className="gap-[3px]">
429 <View className="flex-row items-center justify-between gap-2">
430 <Text
431 className="flex-1 text-base font-t3-medium text-drawer-foreground"
432 numberOfLines={1}
433 >
434 {pendingTask.title}
435 </Text>
436 <View className="flex-row items-center gap-2">
437 {statusPill}
438 {timestamp !== null ? (
439 <Text
440 className={cn(
441 "text-xs tabular-nums text-foreground-muted",
442 !compact && "text-drawer-foreground-muted",
443 )}
444 numberOfLines={1}
445 >
446 {timestamp}
447 </Text>
448 ) : null}
449 </View>
450 </View>
451 {subtitleRow}
452 </View>
453 </RowPressable>
454 );
455
456 return (
457 <ControlPillMenu
458 actions={isDraft ? DRAFT_TASK_MENU_ACTIONS : PENDING_TASK_MENU_ACTIONS}
459 onPressAction={handleMenuAction}
460 shouldOpenOnLongPress
461 >
462 {rowContent}
463 </ControlPillMenu>
464 );
465});
466
467/* ─── Thread row ─────────────────────────────────────────────────────── */
468
469const THREAD_ROW_MENU_ACTIONS: MenuAction[] = [
470 { id: "archive", title: "Archive", image: "archivebox" },
471 { id: "rename", title: "Rename", image: "square.and.pencil" },
472 { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
473];
474
475export const ThreadListRow = memo(function ThreadListRow(props: {
476 readonly variant: ThreadListVariant;
477 readonly thread: EnvironmentThreadShell;
478 readonly environmentLabel: string | null;
479 readonly environmentMachine?: EnvironmentMachineKind;
480 /** A message for this thread is waiting in the outbox. */
481 readonly hasQueuedMessages?: boolean;
482 readonly searchMatch?: EnvironmentThreadSearchMatch;
483 readonly searchQuery?: string;
484 readonly isLast: boolean;
485 /** Sidebar only: the thread currently open in the detail pane. */
486 readonly selected?: boolean;
487 /** Defaults to window width minus compact margins. */
488 readonly fullSwipeWidth?: number;
489 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
490 readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
491 readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
492 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
493 readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
494 readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => void;
495 readonly titleRegenerationSupported: boolean;
496 readonly onSwipeableWillOpen: (methods: SwipeableMethods) => void;
497 readonly onSwipeableClose: (methods: SwipeableMethods) => void;
498 readonly simultaneousSwipeGesture?: ComponentProps<
499 typeof ThreadSwipeable
500 >["simultaneousWithExternalGesture"];
501}) {
502 const { width: windowWidth } = useWindowDimensions();
503 const { themeAppearance: colorScheme } = useAppearancePreferences();
504 const compact = props.variant === "compact";
505 const selected = props.selected === true;
506 const visuallySelected = selected && (!compact || Platform.OS === "android");
507 const theme = useUniwindTheme();
508 const screenColor = theme["--color-screen"];
509 const drawerColor = theme["--color-drawer"];
510 const selectedBackgroundColor = theme["--color-thread-selected"];
511
512 const {
513 thread,
514 onSelectThread,
515 onArchiveThread,
516 onDeleteThread,
517 onRenameThread,
518 onRegenerateThreadTitle,
519 onNewThreadOnBranch,
520 } = props;
521 const status = resolveThreadStatus(thread);
522 const pr = useThreadPr(thread);
523 const timestamp = relativeTime(
524 thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
525 );
526 const threadAccessibilityLabel = [
527 thread.title,
528 pr?.accessibilityLabel,
529 props.hasQueuedMessages ? "messages queued to send" : null,
530 ]
531 .filter(Boolean)
532 .join(", ");
533 const subtitleParts = [props.environmentLabel, thread.branch].filter((part): part is string =>
534 Boolean(part),
535 );
536
537 const backgroundColor = compact ? screenColor : drawerColor;
538
539 const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
540 const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]);
541 const handleRename = useCallback(() => onRenameThread(thread), [onRenameThread, thread]);
542 const handleRegenerateTitle = useCallback(
543 () => onRegenerateThreadTitle(thread),
544 [onRegenerateThreadTitle, thread],
545 );
546 const menuActions = useMemo<MenuAction[]>(
547 () => [
548 ...(thread.branch
549 ? [
550 {
551 id: "new-thread-on-branch",
552 title:
553 Platform.OS === "ios" ? "New thread on branch" : `New thread on ${thread.branch}`,
554 image: "square.and.pencil",
555 },
556 ]
557 : []),
558 THREAD_ROW_MENU_ACTIONS[0]!,
559 THREAD_ROW_MENU_ACTIONS[1]!,
560 { id: "copy-thread-id", title: "Copy thread ID", image: "doc.on.doc" },
561 ...buildThreadTitleRegenerationMenuItems({
562 supported: props.titleRegenerationSupported,
563 isRegenerating: thread.titleRegeneration != null,
564 }),
565 THREAD_ROW_MENU_ACTIONS[2]!,
566 ],
567 [props.titleRegenerationSupported, thread.branch, thread.titleRegeneration],
568 );
569 const primaryAction = useMemo(
570 () => ({
571 accessibilityLabel: `Archive ${thread.title}`,
572 icon: "archivebox" as const,
573 label: "Archive",
574 onPress: handleArchive,
575 }),
576 [handleArchive, thread.title],
577 );
578 const handleMenuAction = useCallback(
579 ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
580 if (nativeEvent.event === "new-thread-on-branch") onNewThreadOnBranch(thread);
581 if (nativeEvent.event === "archive") handleArchive();
582 if (nativeEvent.event === "rename") handleRename();
583 if (nativeEvent.event === "copy-thread-id") {
584 copyTextWithHaptic(thread.id, { target: "thread-id" });
585 }
586 if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
587 if (nativeEvent.event === "delete") handleDelete();
588 },
589 [handleArchive, handleDelete, handleRegenerateTitle, handleRename, onNewThreadOnBranch, thread],
590 );
591
592 const statusPill = status ? (
593 <View className={`${status.pillClassName} rounded-full px-1.5 py-0.5`}>
594 <Text className={`text-3xs font-t3-bold ${status.textClassName}`}>{status.label}</Text>
595 </View>
596 ) : null;
597
598 const subtitleRow =
599 subtitleParts.length > 0 || pr !== null ? (
600 <View className="mt-px flex-row items-center gap-1.5">
601 {subtitleParts.length > 0 ? (
602 <>
603 {props.environmentLabel && props.environmentMachine ? (
604 <EnvironmentMachineSymbol
605 kind={props.environmentMachine}
606 size={compact ? 12 : 10}
607 tintColorClassName={
608 compact
609 ? "accent-icon-subtle"
610 : selected
611 ? "accent-thread-selected-foreground-muted"
612 : "accent-drawer-foreground-muted"
613 }
614 />
615 ) : null}
616 <Text
617 className={cn(
618 "shrink",
619 compact ? "text-sm" : "text-xs",
620 visuallySelected
621 ? "text-thread-selected-foreground-muted"
622 : compact
623 ? "text-foreground-muted"
624 : "text-drawer-foreground-muted",
625 )}
626 numberOfLines={1}
627 >
628 {subtitleParts.join(" · ")}
629 </Text>
630 </>
631 ) : null}
632 {pr !== null ? (
633 <View
634 className="flex-row items-center gap-0.5"
635 accessibilityLabel={pr.accessibilityLabel}
636 >
637 {pr.kind === "stack" ? (
638 <SymbolView
639 name="square.3.layers.3d"
640 size={compact ? 13 : 11}
641 tintColor={pullRequestTintColor(pr, colorScheme)}
642 />
643 ) : (
644 <PullRequestIcon
645 size={compact ? 13 : 11}
646 color={pullRequestTintColor(pr, colorScheme)}
647 />
648 )}
649 <Text
650 className={`${compact ? "text-sm" : "text-xs"} font-t3-medium ${pr.textClassName}`}
651 >
652 {pr.label}
653 </Text>
654 </View>
655 ) : null}
656 </View>
657 ) : null;
658
659 const rowContent = (close: () => void) =>
660 compact ? (
661 <RowPressable
662 key={`${thread.environmentId}:${thread.id}`}
663 interactionClassName="bg-row-hover"
664 interactionOpacity={visuallySelected ? 0 : 1}
665 accessibilityHint="Swipe left for archive and delete actions"
666 accessibilityLabel={threadAccessibilityLabel}
667 accessibilityRole="button"
668 className="bg-screen"
669 style={
670 Platform.OS === "android"
671 ? {
672 backgroundColor: visuallySelected ? selectedBackgroundColor : backgroundColor,
673 borderRadius: 20,
674 }
675 : undefined
676 }
677 onPress={() => {
678 close();
679 onSelectThread(thread);
680 }}
681 >
682 <View className="pr-[18px] pt-[10px]" style={{ paddingLeft: THREAD_LIST_COMPACT_INSET }}>
683 <View
684 className={cn(
685 "gap-[3px] pb-[10px]",
686 Platform.OS !== "android" && !props.isLast && "border-b border-separator",
687 )}
688 >
689 <View className="flex-row items-center justify-between gap-2">
690 <Text
691 className={cn(
692 "flex-1 text-lg font-t3-bold",
693 visuallySelected
694 ? "text-thread-selected-foreground"
695 : compact
696 ? "text-foreground"
697 : "text-drawer-foreground",
698 )}
699 numberOfLines={1}
700 >
701 {thread.title}
702 </Text>
703 <View className="flex-row items-center gap-2">
704 {props.hasQueuedMessages ? (
705 <QueuedMessageIcon selected={visuallySelected && Platform.OS !== "android"} />
706 ) : null}
707 {statusPill}
708 <Text
709 className={cn(
710 "text-base tabular-nums",
711 visuallySelected
712 ? "text-thread-selected-foreground-muted"
713 : "text-drawer-foreground-muted",
714 )}
715 >
716 {timestamp}
717 </Text>
718 <SymbolView
719 name="chevron.right"
720 size={13}
721 tintColorClassName="accent-icon-subtle"
722 type="monochrome"
723 />
724 </View>
725 </View>
726 {props.searchMatch ? (
727 <ThreadSearchMatchExcerpt
728 compact
729 sidebar={!compact}
730 match={props.searchMatch}
731 query={props.searchQuery ?? ""}
732 selected={visuallySelected}
733 />
734 ) : null}
735 {subtitleRow}
736 </View>
737 </View>
738 </RowPressable>
739 ) : (
740 <RowPressable
741 key={`${thread.environmentId}:${thread.id}`}
742 interactionClassName="bg-thread-hover"
743 interactionOpacity={visuallySelected ? 0 : 1}
744 accessibilityHint="Opens the thread"
745 accessibilityLabel={threadAccessibilityLabel}
746 accessibilityRole="button"
747 accessibilityState={{ selected }}
748 onPress={() => {
749 close();
750 onSelectThread(thread);
751 }}
752 style={{
753 backgroundColor: visuallySelected ? selectedBackgroundColor : backgroundColor,
754 borderRadius: Platform.OS === "android" ? 20 : SIDEBAR_ROW_RADIUS,
755 minHeight: 64,
756 justifyContent: "center",
757 paddingHorizontal: 12,
758 paddingVertical: 10,
759 }}
760 >
761 <View className="gap-[3px]">
762 <View className="flex-row items-center justify-between gap-2">
763 <Text
764 className={cn(
765 "flex-1 text-base font-t3-medium",
766 visuallySelected
767 ? "text-thread-selected-foreground"
768 : compact
769 ? "text-foreground"
770 : "text-drawer-foreground",
771 )}
772 numberOfLines={1}
773 >
774 {thread.title}
775 </Text>
776 <View className="flex-row items-center gap-2">
777 {props.hasQueuedMessages ? (
778 <QueuedMessageIcon selected={visuallySelected && Platform.OS !== "android"} />
779 ) : null}
780 {statusPill}
781 <Text
782 className={cn(
783 "text-xs tabular-nums",
784 visuallySelected
785 ? "text-thread-selected-foreground-muted"
786 : compact
787 ? "text-foreground-muted"
788 : "text-drawer-foreground-muted",
789 )}
790 numberOfLines={1}
791 >
792 {timestamp}
793 </Text>
794 </View>
795 </View>
796 {props.searchMatch ? (
797 <ThreadSearchMatchExcerpt
798 sidebar={!compact}
799 match={props.searchMatch}
800 query={props.searchQuery ?? ""}
801 selected={visuallySelected}
802 />
803 ) : null}
804 {subtitleRow}
805 </View>
806 </RowPressable>
807 );
808
809 return (
810 <ThreadSwipeable
811 threadKey={`${thread.environmentId}:${thread.id}`}
812 backgroundColor={backgroundColor}
813 containerStyle={
814 Platform.OS === "android"
815 ? { borderRadius: 20, overflow: "hidden", marginHorizontal: 8, marginVertical: 2 }
816 : compact
817 ? undefined
818 : { borderRadius: SIDEBAR_ROW_RADIUS, overflow: "hidden" }
819 }
820 enableTrackpadSwipe
821 fullSwipeWidth={props.fullSwipeWidth ?? windowWidth - 32}
822 onDelete={handleDelete}
823 onSwipeableClose={props.onSwipeableClose}
824 onSwipeableWillOpen={props.onSwipeableWillOpen}
825 primaryAction={primaryAction}
826 resetKey={`${thread.environmentId}:${thread.id}`}
827 simultaneousWithExternalGesture={props.simultaneousSwipeGesture}
828 threadTitle={thread.title}
829 >
830 {(close) => (
831 // Messages-style row actions on long-press. iOS: a real
832 // UIContextMenuInteraction with the row as the zoom preview (needs the
833 // patched @react-native-menu, see
834 // patches/@react-native-menu__menu@2.0.0.patch — in long-press mode the
835 // interaction is hosted by the component view and the underlying
836 // UIButton passes touches through, so row taps keep working). Android:
837 // ControlPillMenu injects onLongPress into the row and anchors the
838 // token-styled dropdown to it; taps and swipes are untouched.
839 <ControlPillMenu
840 actions={menuActions}
841 onPressAction={handleMenuAction}
842 shouldOpenOnLongPress
843 >
844 {rowContent(close)}
845 </ControlPillMenu>
846 )}
847 </ThreadSwipeable>
848 );
849});