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

ThreadNavigationSidebar.tsx

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