import { useAndroidControlSizing } from "../../components/useAndroidControlSizing"; import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider"; import { computeThreadMoveAvailability } from "./threadOrder"; import type { EnvironmentProject, EnvironmentThreadShell, } from "@t3tools/client-runtime/state/shell"; import { threadSearchMatchKey, type EnvironmentThreadSearchMatch, } from "@t3tools/client-runtime/state/thread-search"; import { LegendList } from "@legendapp/list/react-native"; import type { MenuAction } from "@react-native-menu/menu"; import { useAtomValue } from "@effect/atom-react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import type { LayoutChangeEvent, TextInputInstance } from "react-native"; import { Platform, StyleSheet, TextInput, View } from "react-native"; import { GestureDetector, useNativeGesture } from "react-native-gesture-handler"; import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import type { SearchBarCommands } from "react-native-screens"; import { AppText as Text } from "../../components/AppText"; import { CompactBrandTitle } from "../../components/CompactBrandTitle"; import { ControlPillMenu } from "../../components/ControlPill"; import { SymbolView } from "../../components/AppSymbol"; import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass"; import { NativeStackScreenOptions } from "../../native/StackHeader"; import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities"; import { useProjects, useNavigationThreadShells } from "../../state/entities"; import { useThreadSearch } from "../../state/queries"; import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences"; import { usePendingThreadOrder } from "../../state/thread-order"; import { threadListEnvironmentsAtom } from "../../state/server"; import { usePendingNewTasks } from "../../state/use-pending-new-tasks"; import { useQueuedThreadKeys } from "../../state/use-thread-outbox"; import { useWorkspaceState } from "../../state/workspace"; import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry"; import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands"; import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts"; import { useHomeListOptions } from "../home/home-list-options"; import { buildHomeListFilterMenu } from "../home/home-list-filter-menu"; import { buildHomeProjectScopes } from "../home/homeThreadList"; import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions"; import { usePendingTaskListActions } from "../home/usePendingTaskListActions"; import { useThreadListActions } from "../home/useThreadListActions"; import { getConnectionAwareBrandHeaderOptions, WorkspaceConnectionTitle, } from "../home/WorkspaceConnectionTitle"; import { SidebarHeaderActions } from "./sidebar-header-actions"; import { MaterialThreadListToolbar } from "../home/MaterialThreadListToolbar"; import { useMaterialToolbarLayout } from "../../components/useMaterialToolbarLayout"; import { useMaterialFabScroll } from "../home/MaterialFabScrollContext"; import { SidebarFilterButton } from "./sidebar-filter-button"; import { createSidebarHeaderItems } from "./sidebar-native-header-items"; import { SidebarNavigationShell } from "./sidebar-navigation-shell"; import { ThreadListV2PendingRow, ThreadListV2Row, ThreadListV2SettledShelfHeader, ThreadListV2ShowMoreRow, ThreadListV2SnoozedShelfHeader, ThreadListV2WorkingShelfHeader, } from "./thread-list-v2-items"; import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance"; import { buildThreadListV2Items, getThreadListV2OrderedSection, buildThreadListV2ListItems, isThreadListV2ListItem, threadListV2ListItemsAreEqual, threadListInboxReturns, THREAD_LIST_V2_SETTLED_INITIAL_COUNT, THREAD_LIST_V2_SETTLED_PAGE_COUNT, type ThreadListV2ListItem, } from "./threadListV2"; /** The sidebar list: flat v2 rows with queued tasks spliced in, plus a settled "Show more" pager row. */ type SidebarListItem = | ThreadListV2ListItem | { readonly type: "v2-show-more"; readonly key: string; readonly hiddenCount: number }; const SIDEBAR_STICKY_HEADER_HEIGHT = 106; interface ThreadNavigationSidebarProps { readonly width: number; readonly visible: boolean; readonly selectedThreadKey: string | null; readonly onOpenSettings: () => void; readonly onOpenEnvironmentSettings: () => void; readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void; readonly onNewThreadInProject: (project: EnvironmentProject) => void; readonly onSearchQueryChange: (query: string) => void; readonly onSelectThread: (thread: EnvironmentThreadShell) => void; readonly onRequestVisibility: () => void; readonly searchQuery: string; } /** * iPad/large-width sidebar column. * * On iOS the pane is hosted inside its own navigation-inert single-screen * native stack (SidebarNavigationShell) so the header is a real * UINavigationBar: large title, native bar-button items, and a * UISearchController search field — the same chrome a UISplitViewController * column gets. Other platforms keep the custom header chrome. */ export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) { if (Platform.OS !== "ios") { return ; } return ; } function NativeSidebarContainer(props: ThreadNavigationSidebarProps) { return ( ); } function ThreadNavigationSidebarPane( props: ThreadNavigationSidebarProps & { readonly nativeChrome: boolean }, ) { const { themeVariables: materialTheme } = useAppearancePreferences(); const drawerColor = materialTheme["--color-drawer"]; const insets = useSafeAreaInsets(); const { fabClearance } = useAndroidControlSizing(); const projects = useProjects(); const threads = useNavigationThreadShells(); const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState(); const { savedConnectionsById } = useSavedRemoteConnections(); const searchInputRef = useRef(null); const searchBarRef = useRef(null); const openSwipeableRef = useRef(null); const sidebarScrollGesture = useNativeGesture(); const { archiveThread, confirmDeleteThread, settleThread, snoozeThread, unsnoozeThread, unsettleThread, pinThread, unpinThread, setThreadAutoSettle, moveThread, renameThread, regenerateThreadTitle, } = useThreadListActions(); const pendingTasks = usePendingNewTasks(); const queuedThreadKeys = useQueuedThreadKeys(); const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions(); const environments = useMemo( () => Object.values(savedConnectionsById) .map((connection) => ({ environmentId: connection.environmentId, label: connection.environmentLabel, })) .sort((left, right) => left.label.localeCompare(right.label)), [savedConnectionsById], ); const availableEnvironmentIds = useMemo( () => new Set(environments.map((environment) => environment.environmentId)), [environments], ); const { options, setSelectedEnvironmentId } = useHomeListOptions(availableEnvironmentIds); const searchEnvironmentIds = useMemo( () => options.selectedEnvironmentId === null ? workspaceEnvironments .filter((environment) => environment.connectionState === "connected") .map((environment) => environment.environmentId) : workspaceEnvironments.some( (environment) => environment.environmentId === options.selectedEnvironmentId && environment.connectionState === "connected", ) ? [options.selectedEnvironmentId] : [], [options.selectedEnvironmentId, workspaceEnvironments], ); const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery); const threadSearchMatchByKey = useMemo(() => { const matches = new Map(); for (const match of threadSearch.matches) { if (match.source === "user" || match.source === "assistant") { matches.set(threadSearchMatchKey(match), match); } } return matches; }, [threadSearch.matches]); const matchedThreadKeys = useMemo( () => new Set(threadSearch.matches.map(threadSearchMatchKey)), [threadSearch.matches], ); const [selectedProjectKey, setSelectedProjectKey] = useState(null); const projectScopes = useMemo( () => buildHomeProjectScopes({ projects, environmentId: options.selectedEnvironmentId, projectGroupingMode: options.projectGroupingMode, }), [options.projectGroupingMode, options.selectedEnvironmentId, projects], ); const projectFilterOptions = useMemo( () => projectScopes.map((scope) => ({ key: scope.key, label: scope.title, })), [projectScopes], ); const projectTitleByProjectKey = useMemo( () => new Map( projectScopes.flatMap((scope) => scope.projectRefs.map( (projectRef) => [ scopedProjectKey(projectRef.environmentId, projectRef.projectId), scope.title, ] as const, ), ), ), [projectScopes], ); const selectedProjectScope = useMemo( () => selectedProjectKey === null ? null : (projectScopes.find((scope) => scope.key === selectedProjectKey) ?? null), [projectScopes, selectedProjectKey], ); useEffect(() => { if ( selectedProjectKey !== null && !projectFilterOptions.some((project) => project.key === selectedProjectKey) ) { setSelectedProjectKey(null); } }, [projectFilterOptions, selectedProjectKey]); const selectedProjectRefs = useMemo( () => selectedProjectScope === null ? null : new Set( selectedProjectScope.projectRefs.map((projectRef) => scopedProjectKey(projectRef.environmentId, projectRef.projectId), ), ), [selectedProjectScope], ); const projectByKey = useMemo(() => { const map = new Map(); for (const project of projects) { map.set(scopedProjectKey(project.environmentId, project.id), project); } return map; }, [projects]); // Thread List v2 (beta) support — same model as the compact Home list // (HomeScreen.tsx): flat creation-order card block + settled recency tail. // The settled tail renders in pages; expansion resets when the filter // context changes so environment/search flips never inherit a deep page. const [settledVisibleCount, setSettledVisibleCount] = useState( THREAD_LIST_V2_SETTLED_INITIAL_COUNT, ); const settledResetKey = `${options.selectedEnvironmentId ?? "all"}:${selectedProjectKey ?? "all"}:${props.searchQuery.trim()}`; const lastSettledResetKeyRef = useRef(settledResetKey); if (lastSettledResetKeyRef.current !== settledResetKey) { lastSettledResetKeyRef.current = settledResetKey; setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT); } const showMoreSettled = useCallback( () => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT), [], ); const { loaded: shelfPreferencesLoaded, settledShelfExpanded, snoozedShelfExpanded, workingShelfEnabled, workingShelfExpanded, toggleSettledShelf, toggleSnoozedShelf, toggleWorkingShelf, } = useThreadListV2ShelfPreferences(); // The queued-start and snooze helpers need a clock while the pane stays open. const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16)); // Snooze wake times are second-precise; a counter bumped exactly at the // next wake boundary re-runs the partition with a fresh clock so a woken // thread reappears immediately instead of on the next minute tick. const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0); useEffect(() => { // Refresh immediately because the mount-time value can be hours old. setNowMinute(new Date().toISOString().slice(0, 16)); const id = setInterval(() => setNowMinute(new Date().toISOString().slice(0, 16)), 60_000); return () => clearInterval(id); }, []); // Threads on servers without the settlement capability never classify as // settled (the user could neither un-settle nor pin them). const listEnvironments = useAtomValue(threadListEnvironmentsAtom); const { providersByEnvironmentId, machineByEnvironmentId, settlementEnvironmentIds, snoozeEnvironmentIds, pinningEnvironmentIds, autoSettleOptOutEnvironmentIds, pinReorderEnvironmentIds, activeReorderEnvironmentIds, titleRegenerationEnvironmentIds, } = listEnvironments; const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId); const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick); // Up/down menu availability for every card, computed once per section per // rebuild (see computeThreadMoveAvailability): per-thread planner calls made // list construction quadratic, and this list rebuilds on every minute tick. const threadMoveAvailability = useMemo(() => { const sectionAvailability = (section: "pinned" | "active") => computeThreadMoveAvailability({ allThreads: threads, section, pendingOrder, reorderableEnvironmentIds: section === "pinned" ? pinReorderEnvironmentIds : activeReorderEnvironmentIds, ordered: getThreadListV2OrderedSection({ threads, section, pendingOrder, now: new Date().toISOString(), settlementEnvironmentIds, snoozeEnvironmentIds, queuedThreadKeys, }), }); // The Working beta orders the inbox by time, so only pins can move. return new Map([ ...sectionAvailability("pinned"), ...(workingShelfEnabled ? [] : sectionAvailability("active")), ]); }, [ workingShelfEnabled, pinReorderEnvironmentIds, activeReorderEnvironmentIds, threads, pendingOrder, queuedThreadKeys, settlementEnvironmentIds, snoozeEnvironmentIds, nowMinute, snoozeWakeTick, ]); const threadListV2Layout = useMemo(() => { threadListInboxReturns.observe(workingShelfEnabled ? threads : null); return buildThreadListV2Items({ pendingOrder, threads: threads.filter((thread) => thread.archivedAt === null), environmentId: options.selectedEnvironmentId, projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs, searchQuery: props.searchQuery, matchedThreadKeys, settlementEnvironmentIds, snoozeEnvironmentIds, queuedThreadKeys, settledLimit: settledVisibleCount, now: new Date().toISOString(), workingShelfEnabled, workingShelfExpanded, inboxReturnAt: threadListInboxReturns.returnedAt, snoozedShelfExpanded, settledShelfExpanded, selectedThreadKey: props.selectedThreadKey ?? null, }); }, [ workingShelfEnabled, workingShelfExpanded, pendingOrder, queuedThreadKeys, nowMinute, snoozeWakeTick, snoozedShelfExpanded, settledShelfExpanded, props.selectedThreadKey, options.selectedEnvironmentId, props.searchQuery, matchedThreadKeys, settledVisibleCount, settlementEnvironmentIds, snoozeEnvironmentIds, threads, selectedProjectScope, ]); // Re-partition the moment the earliest snooze expires (clamped to the // signed-32-bit setTimeout range; far-future wakes re-arm at the clamp). const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt; useEffect(() => { if (nextSnoozeWakeAt === null) return; const wakeAtMs = Date.parse(nextSnoozeWakeAt); if (Number.isNaN(wakeAtMs)) return; const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647); const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs); return () => clearTimeout(id); // snoozeWakeTick must re-arm the timer even when nextSnoozeWakeAt is // unchanged: after a clamped fire (wake beyond the 32-bit setTimeout // range) the boundary string is identical and the chain would die. }, [nextSnoozeWakeAt, snoozeWakeTick]); const listItems = useMemo(() => { // Queued offline tasks are not thread shells, so the v2 item builder // never sees them; the shared splice puts them below the active block // (mirrors the compact Home v2 list) where they stay visible and // deletable while their environment is offline. Same environment scope // and search filter as the list. const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase(); const v2PendingTasks = pendingTasks.filter( (pendingTask) => (options.selectedEnvironmentId === null || pendingTask.environmentId === options.selectedEnvironmentId) && (selectedProjectRefs === null || selectedProjectRefs.has( scopedProjectKey(pendingTask.environmentId, pendingTask.projectId), )) && (v2SearchQuery.length === 0 || pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)), ); const items: SidebarListItem[] = buildThreadListV2ListItems({ items: threadListV2Layout.items, pendingTasks: v2PendingTasks, workingCount: threadListV2Layout.workingCount, workingShelfExpanded, workingShelfHeaderIndex: threadListV2Layout.workingShelfHeaderIndex, snoozedCount: threadListV2Layout.snoozedCount, snoozedShelfExpanded, snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex, settledCount: threadListV2Layout.settledCount, settledShelfExpanded, settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex, snoozeLabelNow: `${nowMinute}:00.000Z`, snoozeEnvironmentIds, queuedThreadKeys, moveAvailability: threadMoveAvailability, shelfPreferencesLoading: !shelfPreferencesLoaded, }); if (settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0) { items.push({ type: "v2-show-more", key: "v2-show-more", hiddenCount: threadListV2Layout.hiddenSettledCount, }); } return items; }, [ nowMinute, options.selectedEnvironmentId, pendingTasks, props.searchQuery, queuedThreadKeys, threadMoveAvailability, selectedProjectRefs, settledShelfExpanded, shelfPreferencesLoaded, snoozedShelfExpanded, snoozeEnvironmentIds, threadListV2Layout, workingShelfExpanded, ]); const listMenuActions = useMemo( () => [ { id: "environment", title: "Environment", subactions: [ { id: "environment:all", title: "All environments", subtitle: "Show threads from every environment", state: options.selectedEnvironmentId === null ? "on" : "off", }, ...environments.map((environment) => ({ id: `environment:${environment.environmentId}`, title: environment.label, state: options.selectedEnvironmentId === environment.environmentId ? ("on" as const) : ("off" as const), })), ], }, ...(projectFilterOptions.length === 0 ? [] : ([ { id: "project", title: "Project", subactions: [ { id: "project:all", title: "All projects", subtitle: "Show threads from every project", state: selectedProjectKey === null ? "on" : "off", }, ...projectFilterOptions.map((project) => ({ id: `project:${project.key}`, title: project.label, state: selectedProjectKey === project.key ? ("on" as const) : ("off" as const), })), ], }, ] satisfies MenuAction[])), ], [environments, options, projectFilterOptions, selectedProjectKey], ); const handleListMenuAction = useCallback( ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => { const event = nativeEvent.event; if (event === "environment:all") { setSelectedEnvironmentId(null); return; } if (event.startsWith("environment:")) { const environment = environments.find( (candidate) => String(candidate.environmentId) === event.slice("environment:".length), ); if (environment) setSelectedEnvironmentId(environment.environmentId); return; } if (event === "project:all") { setSelectedProjectKey(null); return; } if (event.startsWith("project:")) { const projectKey = event.slice("project:".length); if (projectFilterOptions.some((project) => project.key === projectKey)) { setSelectedProjectKey(projectKey); } return; } }, [environments, projectFilterOptions, setSelectedEnvironmentId], ); const [measuredHeaderHeight, setMeasuredHeaderHeight] = useState(null); const { height, paddingTop, paddingBottom } = useMaterialToolbarLayout(); // The sticky header (title row, search field, optional connection status) // is measured so the list inset always matches its real height — no // hardcoded per-variant constants. const stickyHeaderHeight = measuredHeaderHeight ?? (Platform.OS === "android" ? paddingTop + height + paddingBottom : insets.top + SIDEBAR_STICKY_HEADER_HEIGHT); const topListInset = stickyHeaderHeight + 6; const handleStickyHeaderLayout = useCallback((event: LayoutChangeEvent) => { const nextHeight = event.nativeEvent.layout.height; setMeasuredHeaderHeight((current) => (current === nextHeight ? current : nextHeight)); }, []); const handleSwipeableWillOpen = useCallback((methods: SwipeableMethods) => { if (openSwipeableRef.current !== methods) { openSwipeableRef.current?.close(); openSwipeableRef.current = methods; } }, []); const handleSwipeableClose = useCallback((methods: SwipeableMethods) => { if (openSwipeableRef.current === methods) { openSwipeableRef.current = null; } }, []); const handleSelectThread = useCallback( (thread: EnvironmentThreadShell) => { props.onSelectThread(thread); openSwipeableRef.current?.close(); }, [props.onSelectThread], ); const handleScrollBeginDrag = useCallback(() => { openSwipeableRef.current?.close(); }, []); const onMaterialFabScroll = useMaterialFabScroll(); const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({ onScroll: onMaterialFabScroll, onScrollBeginDrag: handleScrollBeginDrag, }); // The sticky header's project shells and search maps feed row props, so // they have to bust the recycler's memoization — otherwise a row keeps the // blank favicon and fallback title it was first rendered with. The minute // clock deliberately stays out: its per-row text lives on the items, so a // tick only re-renders rows whose displayed text actually moved. const listExtraData = useMemo( () => ({ selectedThreadKey: props.selectedThreadKey ?? "", projectByKey, projectTitleByProjectKey, savedConnectionsById, listEnvironments, threadSearchMatchByKey, // Rows read it for their reorder menu items. workingShelfEnabled, }), [ props.selectedThreadKey, projectByKey, projectTitleByProjectKey, savedConnectionsById, listEnvironments, threadSearchMatchByKey, workingShelfEnabled, ], ); useThreadJumpShortcuts(listItems, handleSelectThread); const sidebarItemsAreEqual = useCallback( (previous: SidebarListItem, item: SidebarListItem): boolean => { if (isThreadListV2ListItem(previous) && isThreadListV2ListItem(item)) { return threadListV2ListItemsAreEqual(previous, item); } if (previous.type === "v2-show-more" && item.type === "v2-show-more") { return previous.hiddenCount === item.hiddenCount; } return false; }, [], ); const focusSearch = useCallback(() => { if (Platform.OS === "android") return false; const focus = () => { if (props.nativeChrome) { searchBarRef.current?.focus(); return; } searchInputRef.current?.focus(); }; if (!props.visible) { props.onRequestVisibility(); setTimeout(focus, 240); } else { focus(); } return true; }, [props.nativeChrome, props.onRequestVisibility, props.visible]); useHardwareKeyboardCommand("focusSearch", focusSearch); const renderListItem = useCallback( ({ item }: { readonly item: SidebarListItem }) => { switch (item.type) { case "v2-pending": { const pendingScopeKey = scopedProjectKey( item.pendingTask.environmentId, item.pendingTask.projectId, ); return ( 1 ? (savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null) : null } environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)} pane="sidebar" showPendingDivider={item.showPendingDivider} onSelectPendingTask={openPendingTask} onDeletePendingTask={confirmDeletePendingTask} /> ); } case "v2-thread": { const thread = item.item.thread; const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId); // Intentional difference from Home: the sidebar never passes // `showTrailingDivider` because its rows render no Home-style row // hairline at all — card rows carry tonal containers in this pane // (the hairline branch is !sidebarPane-only) and slim rows have no // hairline branch. The stamp still rides the shared list items // because Home's boundary suppression consumes it; the sidebar's // only cost is the occasional divider-only equality invalidation, // which re-renders identically. return ( 1 ? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null) : null } environmentMachine={machineByEnvironmentId.get(thread.environmentId)} searchMatch={threadSearchMatchByKey.get( threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id, }), )} searchQuery={props.searchQuery} pane="sidebar" selected={ scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey } fullSwipeWidth={props.width - 20} onSelectThread={handleSelectThread} onDeleteThread={confirmDeleteThread} onArchiveThread={archiveThread} onRenameThread={renameThread} onRegenerateThreadTitle={regenerateThreadTitle} titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)} settlementSupported={settlementEnvironmentIds.has(thread.environmentId)} onSettleThread={settleThread} snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)} pinningSupported={pinningEnvironmentIds.has(thread.environmentId)} autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)} reorderSupported={ item.item.pinned ? pinReorderEnvironmentIds.has(thread.environmentId) : !workingShelfEnabled && activeReorderEnvironmentIds.has(thread.environmentId) } canMoveUp={item.canMoveUp} canMoveDown={item.canMoveDown} onSnoozeThread={snoozeThread} onUnsnoozeThread={unsnoozeThread} onUnsettleThread={unsettleThread} onPinThread={pinThread} onUnpinThread={unpinThread} onSetThreadAutoSettle={setThreadAutoSettle} onMoveThread={moveThread} onSwipeableClose={handleSwipeableClose} onSwipeableWillOpen={handleSwipeableWillOpen} simultaneousSwipeGesture={sidebarScrollGesture} /> ); } case "v2-working-shelf": return ( ); case "v2-snoozed-shelf": return ( ); case "v2-settled-shelf": return ( ); case "v2-show-more": return ( ); } }, [ archiveThread, activeReorderEnvironmentIds, confirmDeletePendingTask, confirmDeleteThread, handleSelectThread, handleSwipeableClose, handleSwipeableWillOpen, machineByEnvironmentId, moveThread, openPendingTask, pinReorderEnvironmentIds, pinThread, pinningEnvironmentIds, autoSettleOptOutEnvironmentIds, autoSettleOptOutEnvironmentIds, setThreadAutoSettle, projectByKey, projectTitleByProjectKey, regenerateThreadTitle, renameThread, props.onNewThreadOnBranch, props.searchQuery, props.selectedThreadKey, props.width, savedConnectionsById, resolveProviderInstance, providersByEnvironmentId, threadSearchMatchByKey, titleRegenerationEnvironmentIds, settleThread, settlementEnvironmentIds, showMoreSettled, sidebarScrollGesture, snoozeEnvironmentIds, snoozeThread, toggleSettledShelf, toggleSnoozedShelf, toggleWorkingShelf, unpinThread, unsettleThread, unsnoozeThread, workingShelfEnabled, ], ); // The list ignores sort/group options, so only the environment and project // filters can light the "customized" state. const filterCustomized = options.selectedEnvironmentId !== null || selectedProjectKey !== null; const filterIcon = filterCustomized ? "line.3.horizontal.decrease.circle.fill" : "line.3.horizontal.decrease.circle"; const filterMenu = useMemo( () => buildHomeListFilterMenu({ environments, projects: projectFilterOptions, selectedEnvironmentId: options.selectedEnvironmentId, selectedProjectKey, onEnvironmentChange: setSelectedEnvironmentId, onProjectChange: setSelectedProjectKey, }), [environments, options, projectFilterOptions, selectedProjectKey, setSelectedEnvironmentId], ); const nativeHeaderItems = useMemo( () => createSidebarHeaderItems({ filterIcon, filterMenu, onOpenSettings: props.onOpenSettings, }), [filterIcon, filterMenu, props.onOpenSettings], ); // Snoozed threads need no special case: the shelf header is a list row // even while collapsed. const listEmpty = ( {catalogState.isLoadingConnections ? "Loading threads…" : Platform.OS === "android" && !catalogState.hasConnections ? "No environments connected" : props.searchQuery.trim().length > 0 ? threadSearch.isPending ? "Searching thread messages…" : "No matching threads" : selectedProjectScope !== null ? `No threads in ${selectedProjectScope.title}` : "No threads yet"} ); if (props.nativeChrome) { return ( <> { props.onSearchQueryChange(""); }, onChangeText: (event) => { props.onSearchQueryChange(event.nativeEvent.text); }, }, unstable_headerRightItems: () => nativeHeaderItems, }} /> item.type} itemsAreEqual={sidebarItemsAreEqual} keyExtractor={(item) => item.key} renderItem={renderListItem} automaticallyAdjustsScrollIndicatorInsets={NATIVE_LIQUID_GLASS_SUPPORTED} contentInsetAdjustmentBehavior={ NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never" } contentContainerStyle={[ styles.threadListContent, Platform.OS === "android" ? { paddingHorizontal: 0 } : null, { paddingBottom: Math.max(insets.bottom, 16) + 16, paddingTop: 6, }, ]} keyboardDismissMode="on-drag" keyboardShouldPersistTaps="handled" {...scrollGateHandlers} recycleItems scrollEventThrottle={16} showsVerticalScrollIndicator={false} style={styles.threadList} ListEmptyComponent={listEmpty} /> ); } return ( {Platform.OS === "android" && listItems.length === 0 ? ( {listEmpty} ) : ( item.type} itemsAreEqual={sidebarItemsAreEqual} keyExtractor={(item) => item.key} renderItem={renderListItem} contentContainerStyle={[ styles.threadListContent, Platform.OS === "android" ? { paddingHorizontal: 0 } : null, { paddingBottom: Platform.OS === "android" ? Math.max(insets.bottom, 16) + fabClearance - insets.bottom : 16 + insets.bottom, paddingTop: Platform.OS === "android" ? 6 : topListInset, }, ]} keyboardDismissMode="on-drag" keyboardShouldPersistTaps="handled" {...scrollGateHandlers} recycleItems scrollEventThrottle={16} showsVerticalScrollIndicator={false} style={styles.threadList} ListEmptyComponent={listEmpty} /> )} {Platform.OS === "android" ? ( ) : ( {/* Title slot doubles as the connection status surface: while an environment reconnects, the brand fades to a status label in place (no layout shift in the list below). */} } /> )} ); } const styles = StyleSheet.create({ threadList: { flex: 1, }, threadListContent: { paddingHorizontal: 8, }, });