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