Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadNavigationSidebar.tsx

1,346 lines49.7 KB

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