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

ThreadNavigationSidebar.tsx

1,406 lines52.3 KB

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