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