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