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

ThreadNavigationSidebar.tsx

1,348 lines50.2 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 screenColor = materialTheme["--color-screen"];
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={Platform.OS === "android" ? "screen" : "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={Platform.OS === "android" ? "screen" : "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={Platform.OS === "android" ? "screen" : "sidebar"}
928 />
929 );
930 case "v2-show-more":
931 return (
932 <ThreadListV2ShowMoreRow hiddenCount={item.hiddenCount} onPress={showMoreSettled} />
933 );
934 case "header":
935 return (
936 <ThreadListGroupHeader
937 variant={Platform.OS === "android" ? "compact" : "sidebar"}
938 collapsed={item.collapsed}
939 isFirst={item.isFirst}
940 groupKey={item.group.key}
941 onGroupAction={updateGroupDisplay}
942 // Same gating as the compact Home list: aggregated groups have no
943 // single target project, and pending-project groups hold a
944 // placeholder shell rather than a real project.
945 newThreadTarget={item.group.newThreadTarget}
946 onNewThread={props.onNewThreadInProject}
947 project={item.group.representative}
948 threadCount={item.group.threads.length + item.group.pendingTasks.length}
949 title={item.group.title}
950 />
951 );
952 case "pending-task":
953 return (
954 <PendingTaskListRow
955 variant={Platform.OS === "android" ? "compact" : "sidebar"}
956 pendingTask={item.pendingTask}
957 environmentLabel={
958 savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null
959 }
960 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
961 isLast={item.isLast}
962 onSelectPendingTask={openPendingTask}
963 onDeletePendingTask={confirmDeletePendingTask}
964 />
965 );
966 case "thread": {
967 const thread = item.thread;
968 return (
969 <ThreadListRow
970 onNewThreadOnBranch={props.onNewThreadOnBranch}
971 variant="sidebar"
972 thread={thread}
973 hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
974 environmentLabel={
975 savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
976 }
977 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
978 isLast={item.isLast}
979 searchMatch={threadSearchMatchByKey.get(
980 threadSearchMatchKey({
981 environmentId: thread.environmentId,
982 threadId: thread.id,
983 }),
984 )}
985 searchQuery={props.searchQuery}
986 selected={
987 scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
988 }
989 fullSwipeWidth={props.width - 20}
990 onArchiveThread={archiveThread}
991 onDeleteThread={confirmDeleteThread}
992 onRenameThread={renameThread}
993 onRegenerateThreadTitle={regenerateThreadTitle}
994 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
995 onSelectThread={handleSelectThread}
996 onSwipeableClose={handleSwipeableClose}
997 onSwipeableWillOpen={handleSwipeableWillOpen}
998 simultaneousSwipeGesture={sidebarScrollGesture}
999 />
1000 );
1002 case "show-more":
1003 return (
1004 <ThreadListShowMoreRow
1005 variant={Platform.OS === "android" ? "compact" : "sidebar"}
1006 hiddenCount={item.hiddenCount}
1007 canShowLess={item.canShowLess}
1008 groupKey={item.groupKey}
1009 onGroupAction={updateGroupDisplay}
1010 />
1011 );
1013 },
1015 archiveThread,
1016 activeReorderEnvironmentIds,
1017 threadMovePlanners,
1018 pendingOrder,
1019 queuedThreadKeys,
1020 confirmDeletePendingTask,
1021 confirmDeleteThread,
1022 handleSelectThread,
1023 handleSwipeableClose,
1024 handleSwipeableWillOpen,
1025 machineByEnvironmentId,
1026 moveThread,
1027 openPendingTask,
1028 pinReorderEnvironmentIds,
1029 pinThread,
1030 pinningEnvironmentIds,
1031 projectByKey,
1032 projectTitleByProjectKey,
1033 regenerateThreadTitle,
1034 renameThread,
1035 props.onNewThreadInProject,
1036 props.onNewThreadOnBranch,
1037 props.searchQuery,
1038 props.selectedThreadKey,
1039 props.width,
1040 savedConnectionsById,
1041 providersByEnvironmentId,
1042 shelfPreferencesLoaded,
1043 threadSearchMatchByKey,
1044 titleRegenerationEnvironmentIds,
1045 settleThread,
1046 settlementEnvironmentIds,
1047 showMoreSettled,
1048 sidebarScrollGesture,
1049 snoozeEnvironmentIds,
1050 snoozeThread,
1051 nowMinute,
1052 toggleSettledShelf,
1053 toggleSnoozedShelf,
1054 unpinThread,
1055 unsettleThread,
1056 unsnoozeThread,
1057 updateGroupDisplay,
1058 ],
1059 );
1060 // v2 ignores the sort/group options, so only the environment filter can
1061 // light the "customized" state while the beta is on.
1062 const filterCustomized = threadListV2Enabled
1063 ? options.selectedEnvironmentId !== null || selectedProjectKey !== null
1064 : hasCustomHomeListOptions({ ...options, selectedProjectKey });
1065 const filterIcon = filterCustomized
1066 ? "line.3.horizontal.decrease.circle.fill"
1067 : "line.3.horizontal.decrease.circle";
1068 const filterMenu = useMemo(
1069 () =>
1070 buildHomeListFilterMenu({
1071 environments,
1072 projects: projectFilterOptions,
1073 selectedEnvironmentId: options.selectedEnvironmentId,
1074 selectedProjectKey,
1075 projectSortOrder: options.projectSortOrder,
1076 threadSortOrder: options.threadSortOrder,
1077 onEnvironmentChange: setSelectedEnvironmentId,
1078 onProjectChange: setSelectedProjectKey,
1079 onProjectSortOrderChange: setProjectSortOrder,
1080 onThreadSortOrderChange: setThreadSortOrder,
1081 listOrganization: !threadListV2Enabled,
1082 }),
1084 environments,
1085 options,
1086 projectFilterOptions,
1087 selectedProjectKey,
1088 setProjectSortOrder,
1089 setSelectedEnvironmentId,
1090 setThreadSortOrder,
1091 threadListV2Enabled,
1092 ],
1093 );
1094 const nativeHeaderItems = useMemo(
1095 () =>
1096 createSidebarHeaderItems({
1097 filterIcon,
1098 filterMenu,
1099 onOpenSettings: props.onOpenSettings,
1100 }),
1101 [filterIcon, filterMenu, props.onOpenSettings],
1102 );
1103 // Snoozed threads need no special case: the shelf header is a list row
1104 // even while collapsed.
1105 const listEmpty = (
1106 <Text
1107 className={
1108 Platform.OS === "android"
1109 ? "px-4 py-4 text-center text-sm text-foreground-muted"
1110 : "px-2 py-4 text-sm text-foreground-muted"
1113 {catalogState.isLoadingConnections
1114 ? "Loading threads…"
1115 : Platform.OS === "android" && !catalogState.hasConnections
1116 ? "No environments connected"
1117 : props.searchQuery.trim().length > 0
1118 ? threadSearch.isPending
1119 ? "Searching thread messages…"
1120 : "No matching threads"
1121 : selectedProjectScope !== null
1122 ? `No threads in ${selectedProjectScope.title}`
1123 : "No threads yet"}
1124 </Text>
1125 );
1126​
1127 if (props.nativeChrome) {
1128 return (
1129 <>
1130 <NativeStackScreenOptions
1131 optionsVersion={[nativeHeaderItems, props.width]}
1132 options={{
1133 // Re-applies the shell's static brand slot with the
1134 // connection-status swap so reconnects surface in the header
1135 // instead of shifting the list.
1136 ...getConnectionAwareBrandHeaderOptions({
1137 headerWidth: props.width,
1138 trailingItemCount: nativeHeaderItems.length,
1139 onOpenEnvironments: props.onOpenEnvironmentSettings,
1140 fallbackTitleStyle: { fontSize: 18, fontWeight: "800" },
1141 }),
1142 headerSearchBarOptions: {
1143 ref: searchBarRef,
1144 autoCapitalize: "none",
1145 hideNavigationBar: false,
1146 // Keep the search bar pinned under the title — UIKit's default
1147 // hidesSearchBarWhenScrolling collapses it on scroll.
1148 hideWhenScrolling: false,
1149 obscureBackground: false,
1150 placeholder: "Search",
1151 placement: "stacked",
1152 onCancelButtonPress: () => {
1153 props.onSearchQueryChange("");
1154 },
1155 onChangeText: (event) => {
1156 props.onSearchQueryChange(event.nativeEvent.text);
1157 },
1158 },
1159 unstable_headerRightItems: () => nativeHeaderItems,
1160 }}
1161 />
1162 <View className="flex-1">
1163 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1164 <GestureDetector gesture={sidebarScrollGesture}>
1165 <LegendList
1166 data={listItems}
1167 drawDistance={500}
1168 estimatedItemSize={64}
1169 extraData={listExtraData}
1170 getItemType={(item) => item.type}
1171 itemsAreEqual={sidebarItemsAreEqual}
1172 keyExtractor={(item) => item.key}
1173 renderItem={renderListItem}
1174 automaticallyAdjustsScrollIndicatorInsets={NATIVE_LIQUID_GLASS_SUPPORTED}
1175 contentInsetAdjustmentBehavior={
1176 NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never"
1178 contentContainerStyle={[
1179 styles.threadListContent,
1180 Platform.OS === "android" ? { paddingHorizontal: 0 } : null,
1182 paddingBottom: Math.max(insets.bottom, 16) + 16,
1183 paddingTop: 6,
1184 },
1185 ]}
1186 keyboardDismissMode="on-drag"
1187 keyboardShouldPersistTaps="handled"
1188 {...scrollGateHandlers}
1189 recycleItems
1190 scrollEventThrottle={16}
1191 showsVerticalScrollIndicator={false}
1192 style={styles.threadList}
1193 ListEmptyComponent={listEmpty}
1194 />
1195 </GestureDetector>
1196 </SwipeableScrollGateProvider>
1197 </View>
1198 </>
1199 );
1201​
1202 return (
1203 <View
1204 testID="thread-navigation-sidebar"
1205 className={
1206 Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 border-r border-border bg-drawer"
1208 style={{ width: props.width }}
1210 <View
1211 className="flex-1"
1212 style={
1213 Platform.OS === "android"
1214 ? {
1215 marginTop: stickyHeaderHeight,
1216 marginHorizontal: 4,
1217 paddingBottom: insets.bottom,
1218 backgroundColor: screenColor,
1219 borderTopLeftRadius: 28,
1220 borderTopRightRadius: 28,
1221 overflow: "hidden",
1223 : { paddingBottom: insets.bottom }
1226 {Platform.OS === "android" && listItems.length === 0 ? (
1227 <View className="flex-1 items-center justify-center">{listEmpty}</View>
1228 ) : (
1229 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1230 <GestureDetector gesture={sidebarScrollGesture}>
1231 <LegendList
1232 data={listItems}
1233 drawDistance={500}
1234 estimatedItemSize={64}
1235 extraData={listExtraData}
1236 getItemType={(item) => item.type}
1237 itemsAreEqual={sidebarItemsAreEqual}
1238 keyExtractor={(item) => item.key}
1239 renderItem={renderListItem}
1240 contentContainerStyle={[
1241 styles.threadListContent,
1242 Platform.OS === "android" ? { paddingHorizontal: 0 } : null,
1244 paddingBottom:
1245 Platform.OS === "android"
1246 ? Math.max(insets.bottom, 16) + 148 - insets.bottom
1247 : 16 + insets.bottom,
1248 paddingTop: Platform.OS === "android" ? 6 : topListInset,
1249 },
1250 ]}
1251 keyboardDismissMode="on-drag"
1252 keyboardShouldPersistTaps="handled"
1253 {...scrollGateHandlers}
1254 recycleItems
1255 scrollEventThrottle={16}
1256 showsVerticalScrollIndicator={false}
1257 style={styles.threadList}
1258 ListEmptyComponent={listEmpty}
1259 />
1260 </GestureDetector>
1261 </SwipeableScrollGateProvider>
1262 )}
1263 </View>
1264​
1265 {Platform.OS === "android" ? (
1266 <MaterialThreadListToolbar
1267 sidebar
1268 onLayout={handleStickyHeaderLayout}
1269 searchQuery={props.searchQuery}
1270 onSearchQueryChange={props.onSearchQueryChange}
1271 filterActions={listMenuActions}
1272 filterCustomized={filterCustomized}
1273 onFilterAction={handleListMenuAction}
1274 onOpenSettings={props.onOpenSettings}
1275 onOpenEnvironments={props.onOpenEnvironmentSettings}
1276 onRequestVisibility={props.onRequestVisibility}
1277 />
1278 ) : (
1279 <View
1280 className="absolute inset-x-0 top-0 z-[4] bg-drawer"
1281 collapsable={false}
1282 onLayout={handleStickyHeaderLayout}
1283 pointerEvents="auto"
1284 style={{ paddingTop: insets.top }}
1286 <View className="h-[50px] flex-row items-end gap-0.5 pr-2 pl-5">
1287 {/* Title slot doubles as the connection status surface: while an
1288 environment reconnects, the brand fades to a status label in
1289 place (no layout shift in the list below). */}
1290 <WorkspaceConnectionTitle
1291 grow
1292 onPress={props.onOpenEnvironmentSettings}
1293 size="pageTitle"
1294 brand={
1295 <View className="h-11 flex-1 justify-center">
1296 <CompactBrandTitle allowFontScaling={false} />
1297 </View>
1299 />
1300 <View className="flex-row items-center gap-2.5">
1301 <ControlPillMenu actions={listMenuActions} onPressAction={handleListMenuAction}>
1302 <SidebarFilterButton
1303 accessibilityLabel="Filter and sort threads"
1304 icon={filterIcon}
1305 />
1306 </ControlPillMenu>
1307 <SidebarHeaderActions onOpenSettings={props.onOpenSettings} />
1308 </View>
1309 </View>
1310​
1311 <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]">
1312 <SymbolView
1313 name="magnifyingglass"
1314 size={15}
1315 tintColorClassName="accent-foreground-muted"
1316 type="monochrome"
1317 />
1318 <TextInput
1319 ref={searchInputRef}
1320 accessibilityLabel="Search threads"
1321 autoCapitalize="none"
1322 autoCorrect={false}
1323 clearButtonMode="while-editing"
1324 onChangeText={props.onSearchQueryChange}
1325 placeholder="Search"
1326 placeholderTextColorClassName="accent-placeholder"
1327 selectionColorClassName={undefined}
1328 cursorColorClassName={undefined}
1329 selectionHandleColorClassName={undefined}
1330 returnKeyType="search"
1331 className="h-[34px] flex-1 px-0 py-0 font-sans text-base text-foreground"
1332 value={props.searchQuery}
1333 />
1334 </View>
1335 </View>
1336 )}
1337 </View>
1338 );
1340​
1341const styles = StyleSheet.create({
1342 threadList: {
1343 flex: 1,
1344 },
1345 threadListContent: {
1346 paddingHorizontal: 8,
1347 },
1348});