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

ThreadNavigationSidebar.tsx

1,352 lines50.1 KB

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