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