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

ThreadNavigationSidebar.tsx

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