Open History to see the last commit
1import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
2import { createThreadMovePlanner } from "./threadOrder";
3import type {
4 EnvironmentProject,
5 EnvironmentThreadShell,
6} from "@t3tools/client-runtime/state/shell";
7import {
8 threadSearchMatchKey,
9 type EnvironmentThreadSearchMatch,
10} from "@t3tools/client-runtime/state/thread-search";
11import { LegendList } from "@legendapp/list/react-native";
12import type { MenuAction } from "@react-native-menu/menu";
13import { useAtomValue } from "@effect/atom-react";
14import { useCallback, useEffect, useMemo, useRef, useState } from "react";
15import type { LayoutChangeEvent } from "react-native";
16import { Platform, Pressable, StyleSheet, TextInput, View } from "react-native";
17import { Gesture, GestureDetector } from "react-native-gesture-handler";
18import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
19import { useSafeAreaInsets } from "react-native-safe-area-context";
20import type { SearchBarCommands } from "react-native-screens";
21
22import { AppText as Text } from "../../components/AppText";
23import { CompactBrandTitle } from "../../components/CompactBrandTitle";
24import { ControlPillMenu } from "../../components/ControlPill";
25import { SymbolView } from "../../components/AppSymbol";
26import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
27import { NativeStackScreenOptions } from "../../native/StackHeader";
28import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
29import { useProjects, useNavigationThreadShells } from "../../state/entities";
30import { useThreadSearch } from "../../state/queries";
31import { useThreadListV2Enabled } from "./use-thread-list-v2-enabled";
32import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
33import { usePendingThreadOrder } from "../../state/thread-order";
34import { threadListEnvironmentsAtom } from "../../state/server";
35import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
36import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
37import { useWorkspaceState } from "../../state/workspace";
38import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
39import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
40import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
41import {
42 hasCustomHomeListOptions,
43 PROJECT_SORT_OPTIONS,
44 THREAD_SORT_OPTIONS,
45 useHomeListOptions,
46} from "../home/home-list-options";
47import { buildHomeListFilterMenu } from "../home/home-list-filter-menu";
48import {
49 buildHomeListLayout,
50 DEFAULT_GROUP_DISPLAY_STATE,
51 EMPTY_HOME_LIST_LAYOUT,
52 homeListItemsAreEqual,
53 nextGroupDisplayState,
54 type HomeGroupDisplayAction,
55 type HomeGroupDisplayState,
56 type HomeListItem,
57} from "../home/homeListItems";
58import { buildHomeProjectScopes, buildHomeThreadGroups } from "../home/homeThreadList";
59import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions";
60import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
61import { useThreadListActions } from "../home/useThreadListActions";
62import {
63 getConnectionAwareBrandHeaderOptions,
64 WorkspaceConnectionTitle,
65} from "../home/WorkspaceConnectionTitle";
66import { SidebarHeaderActions } from "./sidebar-header-actions";
67import { SidebarFilterButton } from "./sidebar-filter-button";
68import { createSidebarHeaderItems } from "./sidebar-native-header-items";
69import { SidebarNavigationShell } from "./sidebar-navigation-shell";
70import {
71 PendingTaskListRow,
72 ThreadListGroupHeader,
73 ThreadListRow,
74 ThreadListShowMoreRow,
75} from "./thread-list-items";
76import {
77 ThreadListV2PendingRow,
78 ThreadListV2Row,
79 ThreadListV2SettledShelfHeader,
80 ThreadListV2SnoozedShelfHeader,
81} from "./thread-list-v2-items";
82import {
83 buildThreadListV2Items,
84 getThreadListV2OrderedSection,
85 buildThreadListV2ListItems,
86 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
87 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
88 type ThreadListV2ListItem,
89} from "./threadListV2";
90
91/** The sidebar list serves both lists: v1 grouped items or, when the Thread
92 List v2 beta is on, flat v2 rows with queued tasks spliced in, and a settled
93 "Show more" pager. */
94type SidebarListItem =
95 | HomeListItem
96 | ThreadListV2ListItem
97 | { readonly type: "v2-show-more"; readonly key: string; readonly hiddenCount: number };
98
99const SIDEBAR_STICKY_HEADER_HEIGHT = 106;
100
101interface ThreadNavigationSidebarProps {
102 readonly width: number;
103 readonly visible: boolean;
104 readonly selectedThreadKey: string | null;
105 readonly onOpenSettings: () => void;
106 readonly onOpenEnvironmentSettings: () => void;
107 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
108 readonly onNewThreadInProject: (project: EnvironmentProject) => void;
109 readonly onSearchQueryChange: (query: string) => void;
110 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
111 readonly onRequestVisibility: () => void;
112 readonly searchQuery: string;
113}
114
115/**
116 * iPad/large-width sidebar column.
117 *
118 * On iOS the pane is hosted inside its own navigation-inert single-screen
119 * native stack (SidebarNavigationShell) so the header is a real
120 * UINavigationBar: large title, native bar-button items, and a
121 * UISearchController search field — the same chrome a UISplitViewController
122 * column gets. Other platforms keep the custom header chrome.
123 */
124export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) {
125 if (Platform.OS !== "ios") {
126 return <ThreadNavigationSidebarPane {...props} nativeChrome={false} />;
127 }
128 return <NativeSidebarContainer {...props} />;
129}
130
131function NativeSidebarContainer(props: ThreadNavigationSidebarProps) {
132 return (
133 <View
134 testID="thread-navigation-sidebar"
135 className="flex-1 border-border bg-drawer"
136 style={{ borderRightWidth: StyleSheet.hairlineWidth, width: props.width }}
137 >
138 <SidebarNavigationShell>
139 <ThreadNavigationSidebarPane {...props} nativeChrome />
140 </SidebarNavigationShell>
141 </View>
142 );
143}
144
145function ThreadNavigationSidebarPane(
146 props: ThreadNavigationSidebarProps & { readonly nativeChrome: boolean },
147) {
148 const { materialYouStyleLayoutActive, themeVariables: materialTheme } =
149 useAppearancePreferences();
150 const screenColor = materialTheme["--color-screen"];
151 const mutedColor = materialTheme["--color-foreground-muted"];
152
153 const insets = useSafeAreaInsets();
154 const projects = useProjects();
155 const threads = useNavigationThreadShells();
156 const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
157 const { savedConnectionsById } = useSavedRemoteConnections();
158 const searchInputRef = useRef<TextInput>(null);
159 const searchBarRef = useRef<SearchBarCommands>(null);
160 const openSwipeableRef = useRef<SwipeableMethods | null>(null);
161 const sidebarScrollGesture = useMemo(() => Gesture.Native(), []);
162 const {
163 archiveThread,
164 confirmDeleteThread,
165 settleThread,
166 snoozeThread,
167 unsnoozeThread,
168 unsettleThread,
169 pinThread,
170 unpinThread,
171 moveThread,
172 renameThread,
173 regenerateThreadTitle,
174 } = useThreadListActions();
175 const threadListV2Enabled = useThreadListV2Enabled();
176 const pendingTasks = usePendingNewTasks();
177 const queuedThreadKeys = useQueuedThreadKeys();
178 const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
179 const environments = useMemo(
180 () =>
181 Object.values(savedConnectionsById)
182 .map((connection) => ({
183 environmentId: connection.environmentId,
184 label: connection.environmentLabel,
185 }))
186 .sort((left, right) => left.label.localeCompare(right.label)),
187 [savedConnectionsById],
188 );
189 const availableEnvironmentIds = useMemo(
190 () => new Set(environments.map((environment) => environment.environmentId)),
191 [environments],
192 );
193 const { options, setSelectedEnvironmentId, setProjectSortOrder, setThreadSortOrder } =
194 useHomeListOptions(availableEnvironmentIds);
195 const searchEnvironmentIds = useMemo(
196 () =>
197 options.selectedEnvironmentId === null
198 ? workspaceEnvironments
199 .filter((environment) => environment.connectionState === "connected")
200 .map((environment) => environment.environmentId)
201 : workspaceEnvironments.some(
202 (environment) =>
203 environment.environmentId === options.selectedEnvironmentId &&
204 environment.connectionState === "connected",
205 )
206 ? [options.selectedEnvironmentId]
207 : [],
208 [options.selectedEnvironmentId, workspaceEnvironments],
209 );
210 const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
211 const threadSearchMatchByKey = useMemo(() => {
212 const matches = new Map<string, EnvironmentThreadSearchMatch>();
213 for (const match of threadSearch.matches) {
214 if (match.source === "user" || match.source === "assistant") {
215 matches.set(threadSearchMatchKey(match), match);
216 }
217 }
218 return matches;
219 }, [threadSearch.matches]);
220 const matchedThreadKeys = useMemo(
221 () => new Set(threadSearch.matches.map(threadSearchMatchKey)),
222 [threadSearch.matches],
223 );
224 const [selectedProjectKey, setSelectedProjectKey] = useState<string | null>(null);
225 const projectScopes = useMemo(
226 () =>
227 buildHomeProjectScopes({
228 projects,
229 environmentId: options.selectedEnvironmentId,
230 projectGroupingMode: options.projectGroupingMode,
231 }),
232 [options.projectGroupingMode, options.selectedEnvironmentId, projects],
233 );
234 const projectFilterOptions = useMemo(
235 () =>
236 projectScopes.map((scope) => ({
237 key: scope.key,
238 label: scope.title,
239 })),
240 [projectScopes],
241 );
242 const projectTitleByProjectKey = useMemo(
243 () =>
244 new Map(
245 projectScopes.flatMap((scope) =>
246 scope.projectRefs.map(
247 (projectRef) =>
248 [
249 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
250 scope.title,
251 ] as const,
252 ),
253 ),
254 ),
255 [projectScopes],
256 );
257 const selectedProjectScope = useMemo(
258 () =>
259 selectedProjectKey === null
260 ? null
261 : (projectScopes.find((scope) => scope.key === selectedProjectKey) ?? null),
262 [projectScopes, selectedProjectKey],
263 );
264 useEffect(() => {
265 if (
266 selectedProjectKey !== null &&
267 !projectFilterOptions.some((project) => project.key === selectedProjectKey)
268 ) {
269 setSelectedProjectKey(null);
270 }
271 }, [projectFilterOptions, selectedProjectKey]);
272 const selectedProjectRefs = useMemo(
273 () =>
274 selectedProjectScope === null
275 ? null
276 : new Set(
277 selectedProjectScope.projectRefs.map((projectRef) =>
278 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
279 ),
280 ),
281 [selectedProjectScope],
282 );
283 const scopedProjects = useMemo(
284 () =>
285 threadListV2Enabled
286 ? []
287 : selectedProjectRefs === null
288 ? projects
289 : projects.filter((project) =>
290 selectedProjectRefs.has(scopedProjectKey(project.environmentId, project.id)),
291 ),
292 [threadListV2Enabled, projects, selectedProjectRefs],
293 );
294 const scopedThreads = useMemo(
295 () =>
296 threadListV2Enabled
297 ? []
298 : selectedProjectRefs === null
299 ? threads
300 : threads.filter((thread) =>
301 selectedProjectRefs.has(scopedProjectKey(thread.environmentId, thread.projectId)),
302 ),
303 [threadListV2Enabled, selectedProjectRefs, threads],
304 );
305 const scopedPendingTasks = useMemo(
306 () =>
307 threadListV2Enabled
308 ? []
309 : selectedProjectRefs === null
310 ? pendingTasks
311 : pendingTasks.filter((pendingTask) =>
312 selectedProjectRefs.has(
313 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
314 ),
315 ),
316 [threadListV2Enabled, pendingTasks, selectedProjectRefs],
317 );
318 const groups = useMemo(
319 () =>
320 threadListV2Enabled
321 ? []
322 : buildHomeThreadGroups({
323 projects: scopedProjects,
324 threads: scopedThreads,
325 pendingTasks: scopedPendingTasks,
326 queuedThreadKeys,
327 environmentId: options.selectedEnvironmentId,
328 searchQuery: props.searchQuery,
329 matchedThreadKeys,
330 projectSortOrder: options.projectSortOrder,
331 threadSortOrder: options.threadSortOrder,
332 projectGroupingMode: options.projectGroupingMode,
333 }),
334 [
335 threadListV2Enabled,
336 queuedThreadKeys,
337 matchedThreadKeys,
338 options,
339 props.searchQuery,
340 scopedPendingTasks,
341 scopedProjects,
342 scopedThreads,
343 ],
344 );
345 const [groupDisplayStates, setGroupDisplayStates] = useState<
346 ReadonlyMap<string, HomeGroupDisplayState>
347 >(() => new Map());
348 const updateGroupDisplay = useCallback((key: string, action: HomeGroupDisplayAction) => {
349 setGroupDisplayStates((previous) => {
350 const next = new Map(previous);
351 next.set(
352 key,
353 nextGroupDisplayState(previous.get(key) ?? DEFAULT_GROUP_DISPLAY_STATE, action),
354 );
355 return next;
356 });
357 }, []);
358 const hasSearchQuery = props.searchQuery.trim().length > 0;
359 const listLayout = useMemo(
360 () =>
361 threadListV2Enabled
362 ? EMPTY_HOME_LIST_LAYOUT
363 : buildHomeListLayout({
364 groups,
365 displayStates: groupDisplayStates,
366 showAllThreads: hasSearchQuery,
367 }),
368 [threadListV2Enabled, groups, groupDisplayStates, hasSearchQuery],
369 );
370 const projectByKey = useMemo(() => {
371 const map = new Map<string, EnvironmentProject>();
372 for (const project of projects) {
373 map.set(scopedProjectKey(project.environmentId, project.id), project);
374 }
375 return map;
376 }, [projects]);
377
378 // Thread List v2 (beta) support — same model as the compact Home list
379 // (HomeScreen.tsx): flat creation-order card block + settled recency tail.
380 // The settled tail renders in pages; expansion resets when the filter
381 // context changes so environment/search flips never inherit a deep page.
382 const [settledVisibleCount, setSettledVisibleCount] = useState(
383 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
384 );
385 const settledResetKey = `${options.selectedEnvironmentId ?? "all"}:${selectedProjectKey ?? "all"}:${props.searchQuery.trim()}`;
386 const lastSettledResetKeyRef = useRef(settledResetKey);
387 if (lastSettledResetKeyRef.current !== settledResetKey) {
388 lastSettledResetKeyRef.current = settledResetKey;
389 setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT);
390 }
391 const showMoreSettled = useCallback(
392 () => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT),
393 [],
394 );
395 const {
396 loaded: shelfPreferencesLoaded,
397 settledShelfExpanded,
398 snoozedShelfExpanded,
399 toggleSettledShelf,
400 toggleSnoozedShelf,
401 } = useThreadListV2ShelfPreferences();
402 // The queued-start and snooze helpers need a clock while the pane stays open.
403 const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
404 // Snooze wake times are second-precise; a counter bumped exactly at the
405 // next wake boundary re-runs the partition with a fresh clock so a woken
406 // thread reappears immediately instead of on the next minute tick.
407 const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
408 useEffect(() => {
409 if (!threadListV2Enabled) return;
410 // Refresh immediately because the mount-time value can be hours old.
411 setNowMinute(new Date().toISOString().slice(0, 16));
412 const id = setInterval(() => setNowMinute(new Date().toISOString().slice(0, 16)), 60_000);
413 return () => clearInterval(id);
414 }, [threadListV2Enabled]);
415 // Threads on servers without the settlement capability never classify as
416 // settled (the user could neither un-settle nor pin them).
417 const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
418 const {
419 providersByEnvironmentId,
420 machineByEnvironmentId,
421 settlementEnvironmentIds,
422 snoozeEnvironmentIds,
423 pinningEnvironmentIds,
424 pinReorderEnvironmentIds,
425 activeReorderEnvironmentIds,
426 titleRegenerationEnvironmentIds,
427 } = listEnvironments;
428 const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
429 const threadMovePlanners = useMemo(() => {
430 const sectionPlanner = (section: "pinned" | "active") =>
431 createThreadMovePlanner({
432 allThreads: threads,
433 section,
434 reorderableEnvironmentIds:
435 section === "pinned" ? pinReorderEnvironmentIds : activeReorderEnvironmentIds,
436 ordered: getThreadListV2OrderedSection({
437 threads,
438 section,
439 pendingOrder,
440 now: new Date().toISOString(),
441 settlementEnvironmentIds,
442 snoozeEnvironmentIds,
443 queuedThreadKeys,
444 }),
445 });
446 return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
447 }, [
448 pinReorderEnvironmentIds,
449 activeReorderEnvironmentIds,
450 threads,
451 pendingOrder,
452 queuedThreadKeys,
453 settlementEnvironmentIds,
454 snoozeEnvironmentIds,
455 nowMinute,
456 snoozeWakeTick,
457 ]);
458 const threadListV2Layout = useMemo(() => {
459 if (!threadListV2Enabled)
460 return {
461 items: [],
462 hiddenSettledCount: 0,
463 snoozedCount: 0,
464 snoozedShelfHeaderIndex: null,
465 settledCount: 0,
466 settledShelfHeaderIndex: null,
467 nextSnoozeWakeAt: null,
468 };
469 return buildThreadListV2Items({
470 pendingOrder,
471 threads: threads.filter((thread) => thread.archivedAt === null),
472 environmentId: options.selectedEnvironmentId,
473 projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
474 searchQuery: props.searchQuery,
475 matchedThreadKeys,
476 settlementEnvironmentIds,
477 snoozeEnvironmentIds,
478 queuedThreadKeys,
479 settledLimit: settledVisibleCount,
480 now: new Date().toISOString(),
481 snoozedShelfExpanded,
482 settledShelfExpanded,
483 selectedThreadKey: props.selectedThreadKey ?? null,
484 });
485 }, [
486 pendingOrder,
487 queuedThreadKeys,
488 nowMinute,
489 snoozeWakeTick,
490 snoozedShelfExpanded,
491 settledShelfExpanded,
492 props.selectedThreadKey,
493 options.selectedEnvironmentId,
494 props.searchQuery,
495 matchedThreadKeys,
496 settledVisibleCount,
497 settlementEnvironmentIds,
498 snoozeEnvironmentIds,
499 threadListV2Enabled,
500 threads,
501 selectedProjectScope,
502 ]);
503 // Re-partition the moment the earliest snooze expires (clamped to the
504 // signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
505 const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
506 useEffect(() => {
507 if (nextSnoozeWakeAt === null) return;
508 const wakeAtMs = Date.parse(nextSnoozeWakeAt);
509 if (Number.isNaN(wakeAtMs)) return;
510 const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);
511 const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);
512 return () => clearTimeout(id);
513 // snoozeWakeTick must re-arm the timer even when nextSnoozeWakeAt is
514 // unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
515 // range) the boundary string is identical and the chain would die.
516 }, [nextSnoozeWakeAt, snoozeWakeTick]);
517 const listItems = useMemo<readonly SidebarListItem[]>(() => {
518 if (!threadListV2Enabled) return listLayout.items;
519 // Queued offline tasks are not thread shells, so the v2 item builder
520 // never sees them; the shared splice puts them below the active block
521 // (mirrors the compact Home v2 list) where they stay visible and
522 // deletable while their environment is offline. Same environment scope
523 // and search filter as the list.
524 const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();
525 const v2PendingTasks = pendingTasks.filter(
526 (pendingTask) =>
527 (options.selectedEnvironmentId === null ||
528 pendingTask.environmentId === options.selectedEnvironmentId) &&
529 (selectedProjectRefs === null ||
530 selectedProjectRefs.has(
531 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
532 )) &&
533 (v2SearchQuery.length === 0 ||
534 pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
535 );
536 const items: SidebarListItem[] = buildThreadListV2ListItems({
537 items: threadListV2Layout.items,
538 pendingTasks: v2PendingTasks,
539 snoozedCount: threadListV2Layout.snoozedCount,
540 snoozedShelfExpanded,
541 snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
542 settledCount: threadListV2Layout.settledCount,
543 settledShelfExpanded,
544 settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
545 snoozeLabelNow: `${nowMinute}:00.000Z`,
546 });
547 if (settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0) {
548 items.push({
549 type: "v2-show-more",
550 key: "v2-show-more",
551 hiddenCount: threadListV2Layout.hiddenSettledCount,
552 });
553 }
554 return items;
555 }, [
556 listLayout.items,
557 nowMinute,
558 options.selectedEnvironmentId,
559 pendingTasks,
560 props.searchQuery,
561 selectedProjectRefs,
562 settledShelfExpanded,
563 snoozedShelfExpanded,
564 threadListV2Enabled,
565 threadListV2Layout,
566 ]);
567 const listMenuActions = useMemo<MenuAction[]>(
568 () => [
569 {
570 id: "environment",
571 title: "Environment",
572 subactions: [
573 {
574 id: "environment:all",
575 title: "All environments",
576 subtitle: "Show threads from every environment",
577 state: options.selectedEnvironmentId === null ? "on" : "off",
578 },
579 ...environments.map((environment) => ({
580 id: `environment:${environment.environmentId}`,
581 title: environment.label,
582 state:
583 options.selectedEnvironmentId === environment.environmentId
584 ? ("on" as const)
585 : ("off" as const),
586 })),
587 ],
588 },
589 ...(projectFilterOptions.length === 0
590 ? []
591 : ([
592 {
593 id: "project",
594 title: "Project",
595 subactions: [
596 {
597 id: "project:all",
598 title: "All projects",
599 subtitle: "Show threads from every project",
600 state: selectedProjectKey === null ? "on" : "off",
601 },
602 ...projectFilterOptions.map((project) => ({
603 id: `project:${project.key}`,
604 title: project.label,
605 state: selectedProjectKey === project.key ? ("on" as const) : ("off" as const),
606 })),
607 ],
608 },
609 ] satisfies MenuAction[])),
610 // v2 lays the list out in fixed creation order — offering sort/group
611 // controls it silently ignores would be a lie. Environment still
612 // scopes the v2 partition, so it stays.
613 ...(threadListV2Enabled
614 ? []
615 : ([
616 {
617 id: "project-sort",
618 title: "Sort projects",
619 subactions: PROJECT_SORT_OPTIONS.map((option) => ({
620 id: `project-sort:${option.value}`,
621 title: option.label,
622 state: options.projectSortOrder === option.value ? "on" : "off",
623 })),
624 },
625 {
626 id: "thread-sort",
627 title: "Sort threads",
628 subactions: THREAD_SORT_OPTIONS.map((option) => ({
629 id: `thread-sort:${option.value}`,
630 title: option.label,
631 state: options.threadSortOrder === option.value ? "on" : "off",
632 })),
633 },
634 ] satisfies MenuAction[])),
635 ],
636 [environments, options, projectFilterOptions, selectedProjectKey, threadListV2Enabled],
637 );
638 const handleListMenuAction = useCallback(
639 ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
640 const event = nativeEvent.event;
641 if (event === "environment:all") {
642 setSelectedEnvironmentId(null);
643 return;
644 }
645 if (event.startsWith("environment:")) {
646 const environment = environments.find(
647 (candidate) => String(candidate.environmentId) === event.slice("environment:".length),
648 );
649 if (environment) setSelectedEnvironmentId(environment.environmentId);
650 return;
651 }
652 if (event === "project:all") {
653 setSelectedProjectKey(null);
654 return;
655 }
656 if (event.startsWith("project:")) {
657 const projectKey = event.slice("project:".length);
658 if (projectFilterOptions.some((project) => project.key === projectKey)) {
659 setSelectedProjectKey(projectKey);
660 }
661 return;
662 }
663 const projectSort = PROJECT_SORT_OPTIONS.find(
664 (option) => `project-sort:${option.value}` === event,
665 );
666 if (projectSort) {
667 setProjectSortOrder(projectSort.value);
668 return;
669 }
670 const threadSort = THREAD_SORT_OPTIONS.find(
671 (option) => `thread-sort:${option.value}` === event,
672 );
673 if (threadSort) {
674 setThreadSortOrder(threadSort.value);
675 return;
676 }
677 },
678 [
679 environments,
680 projectFilterOptions,
681 setProjectSortOrder,
682 setSelectedEnvironmentId,
683 setThreadSortOrder,
684 ],
685 );
686
687 const [measuredHeaderHeight, setMeasuredHeaderHeight] = useState<number | null>(null);
688 // The sticky header (title row, search field, optional connection status)
689 // is measured so the list inset always matches its real height — no
690 // hardcoded per-variant constants.
691 const stickyHeaderHeight = measuredHeaderHeight ?? insets.top + SIDEBAR_STICKY_HEADER_HEIGHT;
692 const topListInset = stickyHeaderHeight + 6;
693 const handleStickyHeaderLayout = useCallback((event: LayoutChangeEvent) => {
694 const nextHeight = Math.round(event.nativeEvent.layout.height);
695 setMeasuredHeaderHeight((current) => (current === nextHeight ? current : nextHeight));
696 }, []);
697 const handleSwipeableWillOpen = useCallback((methods: SwipeableMethods) => {
698 if (openSwipeableRef.current !== methods) {
699 openSwipeableRef.current?.close();
700 openSwipeableRef.current = methods;
701 }
702 }, []);
703 const handleSwipeableClose = useCallback((methods: SwipeableMethods) => {
704 if (openSwipeableRef.current === methods) {
705 openSwipeableRef.current = null;
706 }
707 }, []);
708 const handleSelectThread = useCallback(
709 (thread: EnvironmentThreadShell) => {
710 props.onSelectThread(thread);
711 openSwipeableRef.current?.close();
712 },
713 [props.onSelectThread],
714 );
715 const handleScrollBeginDrag = useCallback(() => {
716 openSwipeableRef.current?.close();
717 }, []);
718 const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({
719 onScrollBeginDrag: handleScrollBeginDrag,
720 });
721 // Project shells load after the first rows draw, so the maps they feed have
722 // to bust the recycler's memoization — otherwise a row keeps the blank
723 // favicon and fallback title it was first rendered with.
724 const listExtraData = useMemo(
725 () => ({
726 selectedThreadKey: props.selectedThreadKey ?? "",
727 projectByKey,
728 projectTitleByProjectKey,
729 savedConnectionsById,
730 listEnvironments,
731 snoozePresetMinute: nowMinute,
732 threadSearchMatchByKey,
733 }),
734 [
735 props.selectedThreadKey,
736 projectByKey,
737 projectTitleByProjectKey,
738 savedConnectionsById,
739 listEnvironments,
740 nowMinute,
741 threadSearchMatchByKey,
742 ],
743 );
744 useThreadJumpShortcuts(listItems, handleSelectThread);
745 const sidebarItemsAreEqual = useCallback(
746 (previous: SidebarListItem, item: SidebarListItem): boolean => {
747 if (previous.type === "v2-thread" && item.type === "v2-thread") {
748 return (
749 previous.key === item.key &&
750 previous.item.thread === item.item.thread &&
751 previous.item.variant === item.item.variant &&
752 previous.item.snoozed === item.item.snoozed &&
753 previous.item.pinned === item.item.pinned &&
754 previous.snoozeWakeLabelText === item.snoozeWakeLabelText
755 );
756 }
757 if (previous.type === "v2-show-more" && item.type === "v2-show-more") {
758 return previous.hiddenCount === item.hiddenCount;
759 }
760 if (previous.type === "v2-pending" && item.type === "v2-pending") {
761 return (
762 previous.pendingTask === item.pendingTask &&
763 previous.showPendingDivider === item.showPendingDivider
764 );
765 }
766 if (previous.type === "v2-snoozed-shelf" && item.type === "v2-snoozed-shelf") {
767 return previous.count === item.count && previous.expanded === item.expanded;
768 }
769 if (previous.type === "v2-settled-shelf" && item.type === "v2-settled-shelf") {
770 return previous.count === item.count && previous.expanded === item.expanded;
771 }
772 if (
773 previous.type === "v2-thread" ||
774 previous.type === "v2-show-more" ||
775 previous.type === "v2-pending" ||
776 previous.type === "v2-snoozed-shelf" ||
777 previous.type === "v2-settled-shelf" ||
778 item.type === "v2-thread" ||
779 item.type === "v2-show-more" ||
780 item.type === "v2-pending" ||
781 item.type === "v2-snoozed-shelf" ||
782 item.type === "v2-settled-shelf"
783 ) {
784 return false;
785 }
786 return homeListItemsAreEqual(previous, item);
787 },
788 [],
789 );
790 const focusSearch = useCallback(() => {
791 const focus = () => {
792 if (props.nativeChrome) {
793 searchBarRef.current?.focus();
794 return;
795 }
796 searchInputRef.current?.focus();
797 };
798 if (!props.visible) {
799 props.onRequestVisibility();
800 setTimeout(focus, 240);
801 } else {
802 focus();
803 }
804 return true;
805 }, [props.nativeChrome, props.onRequestVisibility, props.visible]);
806 useHardwareKeyboardCommand("focusSearch", focusSearch);
807 const renderListItem = useCallback(
808 ({ item }: { readonly item: SidebarListItem }) => {
809 switch (item.type) {
810 case "v2-pending": {
811 const pendingScopeKey = scopedProjectKey(
812 item.pendingTask.environmentId,
813 item.pendingTask.projectId,
814 );
815 return (
816 <ThreadListV2PendingRow
817 pendingTask={item.pendingTask}
818 project={projectByKey.get(pendingScopeKey) ?? null}
819 projectTitle={projectTitleByProjectKey.get(pendingScopeKey)}
820 environmentLabel={
821 Object.keys(savedConnectionsById).length > 1
822 ? (savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null)
823 : null
824 }
825 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
826 pane="sidebar"
827 showPendingDivider={item.showPendingDivider}
828 onSelectPendingTask={openPendingTask}
829 onDeletePendingTask={confirmDeletePendingTask}
830 />
831 );
832 }
833 case "v2-thread": {
834 const thread = item.item.thread;
835 const movePlanner = item.item.pinned
836 ? threadMovePlanners.pinned
837 : threadMovePlanners.active;
838 const movedId = `${thread.environmentId}:${thread.id}`;
839 const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId);
840 return (
841 <ThreadListV2Row
842 onNewThreadOnBranch={props.onNewThreadOnBranch}
843 thread={thread}
844 variant={item.item.variant}
845 hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
846 snoozed={item.item.snoozed}
847 pinned={item.item.pinned}
848 snoozePresetMinute={nowMinute}
849 snoozeWakeLabelText={item.snoozeWakeLabelText}
850 project={projectByKey.get(scopeKey) ?? null}
851 projectTitle={projectTitleByProjectKey.get(scopeKey)}
852 providers={providersByEnvironmentId.get(thread.environmentId)}
853 environmentLabel={
854 Object.keys(savedConnectionsById).length > 1
855 ? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)
856 : null
857 }
858 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
859 searchMatch={threadSearchMatchByKey.get(
860 threadSearchMatchKey({
861 environmentId: thread.environmentId,
862 threadId: thread.id,
863 }),
864 )}
865 searchQuery={props.searchQuery}
866 pane={materialYouStyleLayoutActive ? "screen" : "sidebar"}
867 selected={
868 scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
869 }
870 fullSwipeWidth={props.width - 20}
871 onSelectThread={handleSelectThread}
872 onDeleteThread={confirmDeleteThread}
873 onArchiveThread={archiveThread}
874 onRenameThread={renameThread}
875 onRegenerateThreadTitle={regenerateThreadTitle}
876 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
877 settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
878 onSettleThread={settleThread}
879 snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
880 pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
881 reorderSupported={
882 item.item.pinned
883 ? pinReorderEnvironmentIds.has(thread.environmentId)
884 : activeReorderEnvironmentIds.has(thread.environmentId)
885 }
886 canMoveUp={pendingOrder === null && movePlanner(movedId, "up") !== null}
887 canMoveDown={pendingOrder === null && movePlanner(movedId, "down") !== null}
888 onSnoozeThread={snoozeThread}
889 onUnsnoozeThread={unsnoozeThread}
890 onUnsettleThread={unsettleThread}
891 onPinThread={pinThread}
892 onUnpinThread={unpinThread}
893 onMoveThread={moveThread}
894 onSwipeableClose={handleSwipeableClose}
895 onSwipeableWillOpen={handleSwipeableWillOpen}
896 simultaneousSwipeGesture={sidebarScrollGesture}
897 />
898 );
899 }
900 case "v2-snoozed-shelf":
901 return (
902 <ThreadListV2SnoozedShelfHeader
903 count={item.count}
904 disabled={!shelfPreferencesLoaded}
905 expanded={item.expanded}
906 onToggle={toggleSnoozedShelf}
907 pane={materialYouStyleLayoutActive ? "screen" : "sidebar"}
908 />
909 );
910 case "v2-settled-shelf":
911 return (
912 <ThreadListV2SettledShelfHeader
913 count={item.count}
914 disabled={!shelfPreferencesLoaded}
915 expanded={item.expanded}
916 onToggle={toggleSettledShelf}
917 pane={materialYouStyleLayoutActive ? "screen" : "sidebar"}
918 />
919 );
920 case "v2-show-more":
921 return (
922 <Pressable
923 accessibilityRole="button"
924 accessibilityLabel={`Show ${Math.min(item.hiddenCount, THREAD_LIST_V2_SETTLED_PAGE_COUNT)} more settled threads`}
925 onPress={showMoreSettled}
926 className="mx-4 mt-2 items-center rounded-lg border border-dashed border-border py-2.5"
927 style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
928 >
929 <Text className="text-xs font-t3-medium text-foreground-muted">
930 Show more ({item.hiddenCount} settled hidden)
931 </Text>
932 </Pressable>
933 );
934 case "header":
935 return (
936 <ThreadListGroupHeader
937 variant={materialYouStyleLayoutActive ? "compact" : "sidebar"}
938 collapsed={item.collapsed}
939 isFirst={item.isFirst}
940 groupKey={item.group.key}
941 onGroupAction={updateGroupDisplay}
942 // Same gating as the compact Home list: aggregated groups have no
943 // single target project, and pending-project groups hold a
944 // placeholder shell rather than a real project.
945 newThreadTarget={item.group.newThreadTarget}
946 onNewThread={props.onNewThreadInProject}
947 project={item.group.representative}
948 threadCount={item.group.threads.length + item.group.pendingTasks.length}
949 title={item.group.title}
950 />
951 );
952 case "pending-task":
953 return (
954 <PendingTaskListRow
955 variant={materialYouStyleLayoutActive ? "compact" : "sidebar"}
956 pendingTask={item.pendingTask}
957 environmentLabel={
958 savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null
959 }
960 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
961 isLast={item.isLast}
962 onSelectPendingTask={openPendingTask}
963 onDeletePendingTask={confirmDeletePendingTask}
964 />
965 );
966 case "thread": {
967 const thread = item.thread;
968 return (
969 <ThreadListRow
970 onNewThreadOnBranch={props.onNewThreadOnBranch}
971 variant="sidebar"
972 thread={thread}
973 hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
974 environmentLabel={
975 savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
976 }
977 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
978 isLast={item.isLast}
979 searchMatch={threadSearchMatchByKey.get(
980 threadSearchMatchKey({
981 environmentId: thread.environmentId,
982 threadId: thread.id,
983 }),
984 )}
985 searchQuery={props.searchQuery}
986 selected={
987 scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
988 }
989 fullSwipeWidth={props.width - 20}
990 onArchiveThread={archiveThread}
991 onDeleteThread={confirmDeleteThread}
992 onRenameThread={renameThread}
993 onRegenerateThreadTitle={regenerateThreadTitle}
994 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
995 onSelectThread={handleSelectThread}
996 onSwipeableClose={handleSwipeableClose}
997 onSwipeableWillOpen={handleSwipeableWillOpen}
998 simultaneousSwipeGesture={sidebarScrollGesture}
999 />
1000 );
1001 }
1002 case "show-more":
1003 return (
1004 <ThreadListShowMoreRow
1005 variant={materialYouStyleLayoutActive ? "compact" : "sidebar"}
1006 hiddenCount={item.hiddenCount}
1007 canShowLess={item.canShowLess}
1008 groupKey={item.groupKey}
1009 onGroupAction={updateGroupDisplay}
1010 />
1011 );
1012 }
1013 },
1014 [
1015 materialYouStyleLayoutActive,
1016 archiveThread,
1017 activeReorderEnvironmentIds,
1018 threadMovePlanners,
1019 pendingOrder,
1020 queuedThreadKeys,
1021 confirmDeletePendingTask,
1022 confirmDeleteThread,
1023 handleSelectThread,
1024 handleSwipeableClose,
1025 handleSwipeableWillOpen,
1026 machineByEnvironmentId,
1027 moveThread,
1028 openPendingTask,
1029 pinReorderEnvironmentIds,
1030 pinThread,
1031 pinningEnvironmentIds,
1032 projectByKey,
1033 projectTitleByProjectKey,
1034 regenerateThreadTitle,
1035 renameThread,
1036 props.onNewThreadInProject,
1037 props.onNewThreadOnBranch,
1038 props.searchQuery,
1039 props.selectedThreadKey,
1040 props.width,
1041 savedConnectionsById,
1042 providersByEnvironmentId,
1043 shelfPreferencesLoaded,
1044 threadSearchMatchByKey,
1045 titleRegenerationEnvironmentIds,
1046 settleThread,
1047 settlementEnvironmentIds,
1048 showMoreSettled,
1049 sidebarScrollGesture,
1050 snoozeEnvironmentIds,
1051 snoozeThread,
1052 nowMinute,
1053 toggleSettledShelf,
1054 toggleSnoozedShelf,
1055 unpinThread,
1056 unsettleThread,
1057 unsnoozeThread,
1058 updateGroupDisplay,
1059 ],
1060 );
1061 // v2 ignores the sort/group options, so only the environment filter can
1062 // light the "customized" state while the beta is on.
1063 const filterCustomized = threadListV2Enabled
1064 ? options.selectedEnvironmentId !== null || selectedProjectKey !== null
1065 : hasCustomHomeListOptions({ ...options, selectedProjectKey });
1066 const filterIcon = filterCustomized
1067 ? "line.3.horizontal.decrease.circle.fill"
1068 : "line.3.horizontal.decrease.circle";
1069 const filterMenu = useMemo(
1070 () =>
1071 buildHomeListFilterMenu({
1072 environments,
1073 projects: projectFilterOptions,
1074 selectedEnvironmentId: options.selectedEnvironmentId,
1075 selectedProjectKey,
1076 projectSortOrder: options.projectSortOrder,
1077 threadSortOrder: options.threadSortOrder,
1078 onEnvironmentChange: setSelectedEnvironmentId,
1079 onProjectChange: setSelectedProjectKey,
1080 onProjectSortOrderChange: setProjectSortOrder,
1081 onThreadSortOrderChange: setThreadSortOrder,
1082 listOrganization: !threadListV2Enabled,
1083 }),
1084 [
1085 environments,
1086 options,
1087 projectFilterOptions,
1088 selectedProjectKey,
1089 setProjectSortOrder,
1090 setSelectedEnvironmentId,
1091 setThreadSortOrder,
1092 threadListV2Enabled,
1093 ],
1094 );
1095 const nativeHeaderItems = useMemo(
1096 () =>
1097 createSidebarHeaderItems({
1098 filterIcon,
1099 filterMenu,
1100 onOpenSettings: props.onOpenSettings,
1101 }),
1102 [filterIcon, filterMenu, props.onOpenSettings],
1103 );
1104 // Snoozed threads need no special case: the shelf header is a list row
1105 // even while collapsed.
1106 const listEmpty = (
1107 <Text className="px-2 py-4 text-sm text-foreground-muted">
1108 {catalogState.isLoadingConnections
1109 ? "Loading threads…"
1110 : props.searchQuery.trim().length > 0
1111 ? threadSearch.isPending
1112 ? "Searching thread messages…"
1113 : "No matching threads"
1114 : selectedProjectScope !== null
1115 ? `No threads in ${selectedProjectScope.title}`
1116 : "No threads yet"}
1117 </Text>
1118 );
1119
1120 if (props.nativeChrome) {
1121 return (
1122 <>
1123 <NativeStackScreenOptions
1124 optionsVersion={[nativeHeaderItems, props.width]}
1125 options={{
1126 // Re-applies the shell's static brand slot with the
1127 // connection-status swap so reconnects surface in the header
1128 // instead of shifting the list.
1129 ...getConnectionAwareBrandHeaderOptions({
1130 headerWidth: props.width,
1131 trailingItemCount: nativeHeaderItems.length,
1132 onOpenEnvironments: props.onOpenEnvironmentSettings,
1133 fallbackTitleStyle: { fontSize: 18, fontWeight: "800" },
1134 }),
1135 headerSearchBarOptions: {
1136 ref: searchBarRef,
1137 autoCapitalize: "none",
1138 hideNavigationBar: false,
1139 // Keep the search bar pinned under the title — UIKit's default
1140 // hidesSearchBarWhenScrolling collapses it on scroll.
1141 hideWhenScrolling: false,
1142 obscureBackground: false,
1143 placeholder: "Search",
1144 placement: "stacked",
1145 onCancelButtonPress: () => {
1146 props.onSearchQueryChange("");
1147 },
1148 onChangeText: (event) => {
1149 props.onSearchQueryChange(event.nativeEvent.text);
1150 },
1151 },
1152 unstable_headerRightItems: () => nativeHeaderItems,
1153 }}
1154 />
1155 <View className="flex-1">
1156 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1157 <GestureDetector gesture={sidebarScrollGesture}>
1158 <LegendList
1159 data={listItems}
1160 drawDistance={500}
1161 estimatedItemSize={64}
1162 extraData={listExtraData}
1163 getItemType={(item) => item.type}
1164 itemsAreEqual={sidebarItemsAreEqual}
1165 keyExtractor={(item) => item.key}
1166 renderItem={renderListItem}
1167 automaticallyAdjustsScrollIndicatorInsets={NATIVE_LIQUID_GLASS_SUPPORTED}
1168 contentInsetAdjustmentBehavior={
1169 NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never"
1170 }
1171 contentContainerStyle={[
1172 styles.threadListContent,
1173 materialYouStyleLayoutActive ? { paddingHorizontal: 0 } : null,
1174 {
1175 paddingBottom: Math.max(insets.bottom, 16) + 16,
1176 paddingTop: 6,
1177 },
1178 ]}
1179 keyboardDismissMode="on-drag"
1180 keyboardShouldPersistTaps="handled"
1181 {...scrollGateHandlers}
1182 recycleItems
1183 scrollEventThrottle={16}
1184 showsVerticalScrollIndicator={false}
1185 style={styles.threadList}
1186 ListEmptyComponent={listEmpty}
1187 />
1188 </GestureDetector>
1189 </SwipeableScrollGateProvider>
1190 </View>
1191 </>
1192 );
1193 }
1194
1195 return (
1196 <View
1197 testID="thread-navigation-sidebar"
1198 className="flex-1 border-r border-border bg-drawer"
1199 style={{ width: props.width }}
1200 >
1201 <View
1202 className="flex-1"
1203 style={
1204 materialYouStyleLayoutActive
1205 ? {
1206 marginTop: stickyHeaderHeight,
1207 paddingBottom: insets.bottom,
1208 backgroundColor: screenColor,
1209 borderTopLeftRadius: 28,
1210 borderTopRightRadius: 28,
1211 overflow: "hidden",
1212 }
1213 : { paddingBottom: insets.bottom }
1214 }
1215 >
1216 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1217 <GestureDetector gesture={sidebarScrollGesture}>
1218 <LegendList
1219 data={listItems}
1220 drawDistance={500}
1221 estimatedItemSize={64}
1222 extraData={listExtraData}
1223 getItemType={(item) => item.type}
1224 itemsAreEqual={sidebarItemsAreEqual}
1225 keyExtractor={(item) => item.key}
1226 renderItem={renderListItem}
1227 contentContainerStyle={[
1228 styles.threadListContent,
1229 materialYouStyleLayoutActive ? { paddingHorizontal: 0 } : null,
1230 {
1231 paddingBottom:
1232 Platform.OS === "android"
1233 ? Math.max(insets.bottom, 16) + 88 - insets.bottom
1234 : 16 + insets.bottom,
1235 paddingTop: materialYouStyleLayoutActive ? 6 : topListInset,
1236 },
1237 ]}
1238 keyboardDismissMode="on-drag"
1239 keyboardShouldPersistTaps="handled"
1240 {...scrollGateHandlers}
1241 recycleItems
1242 scrollEventThrottle={16}
1243 showsVerticalScrollIndicator={false}
1244 style={styles.threadList}
1245 ListEmptyComponent={listEmpty}
1246 />
1247 </GestureDetector>
1248 </SwipeableScrollGateProvider>
1249 </View>
1250
1251 <View
1252 className="absolute inset-x-0 top-0 z-[4] bg-drawer"
1253 collapsable={false}
1254 onLayout={handleStickyHeaderLayout}
1255 pointerEvents="auto"
1256 style={{ paddingTop: insets.top }}
1257 >
1258 <View className="h-[50px] flex-row items-end gap-0.5 pr-2 pl-5">
1259 {/* Title slot doubles as the connection status surface: while an
1260 environment reconnects, the brand fades to a status label in
1261 place (no layout shift in the list below). */}
1262 <WorkspaceConnectionTitle
1263 grow
1264 onPress={props.onOpenEnvironmentSettings}
1265 size="pageTitle"
1266 brand={
1267 <View className="h-11 flex-1 justify-center">
1268 <CompactBrandTitle allowFontScaling={false} />
1269 </View>
1270 }
1271 />
1272 <View className="flex-row items-center gap-2.5">
1273 <ControlPillMenu actions={listMenuActions} onPressAction={handleListMenuAction}>
1274 <SidebarFilterButton accessibilityLabel="Filter and sort threads" icon={filterIcon} />
1275 </ControlPillMenu>
1276 <SidebarHeaderActions onOpenSettings={props.onOpenSettings} />
1277 </View>
1278 </View>
1279
1280 <View
1281 className={
1282 materialYouStyleLayoutActive
1283 ? "mx-4 mt-[9px] min-h-12 flex-row items-center gap-2.5 rounded-full border border-input-border bg-input px-3.5"
1284 : "mx-4 mt-[9px] h-[38px] flex-row items-center gap-1.5 rounded-xl bg-sidebar-search pr-2.5 pl-[11px]"
1285 }
1286 >
1287 <SymbolView
1288 name="magnifyingglass"
1289 size={15}
1290 tintColorClassName={"accent-foreground-muted"}
1291 type="monochrome"
1292 />
1293 <TextInput
1294 ref={searchInputRef}
1295 accessibilityLabel="Search threads"
1296 autoCapitalize="none"
1297 autoCorrect={false}
1298 clearButtonMode={materialYouStyleLayoutActive ? "never" : "while-editing"}
1299 onChangeText={props.onSearchQueryChange}
1300 placeholder="Search"
1301 placeholderTextColorClassName={"accent-placeholder"}
1302 returnKeyType="search"
1303 className={
1304 materialYouStyleLayoutActive
1305 ? "flex-1 px-0 py-2.5 font-sans text-base text-foreground"
1306 : "h-[34px] flex-1 px-0 py-0 font-sans text-base text-foreground"
1307 }
1308 value={props.searchQuery}
1309 />
1310 {materialYouStyleLayoutActive && props.searchQuery.length > 0 ? (
1311 <Pressable
1312 accessibilityLabel="Clear search"
1313 hitSlop={10}
1314 onPress={() => props.onSearchQueryChange("")}
1315 >
1316 <SymbolView
1317 name="xmark.circle.fill"
1318 size={17}
1319 tintColor={mutedColor}
1320 type="monochrome"
1321 />
1322 </Pressable>
1323 ) : null}
1324 </View>
1325 </View>
1326 </View>
1327 );
1328}
1329
1330const styles = StyleSheet.create({
1331 threadList: {
1332 flex: 1,
1333 },
1334 threadListContent: {
1335 paddingHorizontal: 8,
1336 },
1337});