16
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
17
import { AnimatedLegendList } from "@legendapp/list/reanimated";
18
import { THREAD_SIDEBAR_ROW_LAYOUT } from "./threadListAnimations";
19
-import type { MenuAction } from "@react-native-menu/menu";
19
import { useAtomValue } from "@effect/atom-react";
20
import { useMemo, useRef, useState } from "react";
21
import { Platform, StyleSheet, View } from "react-native";
22
import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
23
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
25
-import { FLOATING_TABS } from "../workspace/floating-workspace-tabs";
24
+import { FLOATING_TABS } from "../layout/workspace/floating-workspace-tabs";
25
import { useSafeAreaInsets } from "react-native-safe-area-context";
27
-import type { SearchBarCommands } from "react-native-screens";
26
27
import { AppText as Text } from "../../components/ui/AppText";
30
-import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
31
-import { NativeStackScreenOptions } from "../../native/StackHeader";
28
import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
29
import { useProjects, useNavigationThreadShells } from "../../state/entities";
30
import { useThreadSearch } from "../../state/queries";
36
import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
37
import { useWorkspaceState } from "../../state/workspace";
38
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
43
-import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
39
import { useThreadListV2 } from "./useThreadListV2";
40
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
41
import { requestThreadMessageJump } from "./threadMessageJump";
42
import { useThreadListSearchMatches } from "./useThreadListSearchMatches";
43
import { useHomeListOptions } from "../home/home-list-options";
49
-import { buildHomeListFilterMenu } from "../home/home-list-filter-menu";
44
+import { buildHomeListFilterMenuItems } from "../home/home-list-filter-menu";
45
import { buildHomeProjectScopes } from "../home/homeThreadList";
46
import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions";
47
import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
48
import { useThreadListActions } from "../home/useThreadListActions";
54
-import { getConnectionAwareBrandHeaderOptions } from "../home/WorkspaceConnectionTitle";
55
-import { ThreadListToolbar } from "../home/ThreadListToolbar";
49
import { useFabScroll } from "../home/FabScrollContext";
57
-import { createSidebarHeaderItems } from "./sidebar-native-header-items";
58
-import { getCompactBrandHeaderOptions } from "../../components/CompactBrandTitle";
59
-import { StandaloneStack } from "../layout/nested-stacks";
60
-import { pageRoute } from "../layout/route-options";
50
+import { WorkspaceListHeader } from "../layout/workspace/WorkspaceListHeader";
51
+import { WORKSPACE_LIST_SCROLL_INSETS } from "../layout/workspace/workspace-list-insets";
52
+import { WorkspaceSidebarColumn } from "../layout/workspace/WorkspaceSidebarColumn";
53
import {
54
ThreadListV2PendingRow,
55
ThreadListV2Row,
68
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
69
type ThreadListV2ListItem,
70
} from "./threadListV2";
79
-import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";
71
+import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
72
import { NativeScrollView } from "../../native/NativeScrollViewMarker";
73
74
type SidebarListItem =
99
readonly searchQuery: string;
100
}
101
110
-// The iOS sidebar column hosts its own stack so it gets a native bar with the brand title.
111
-const SIDEBAR_COLUMN_OPTIONS = {
112
- ...pageRoute(),
113
- ...getCompactBrandHeaderOptions({ fontSize: 18, fontWeight: "800" }),
114
-};
115
-
102
export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) {
103
return (
104
<ThreadPrDemandProvider visible={props.visible}>
119
- {Platform.OS !== "ios" ? (
120
- <ThreadNavigationSidebarPane {...props} nativeChrome={false} />
121
- ) : (
122
- <NativeSidebarContainer {...props} />
123
- )}
105
+ <WorkspaceSidebarColumn width={props.width}>
106
+ <ThreadNavigationSidebarPane {...props} />
107
+ </WorkspaceSidebarColumn>
108
</ThreadPrDemandProvider>
109
);
110
}
111
128
-function NativeSidebarContainer(props: ThreadNavigationSidebarProps) {
129
- return (
130
- <View
131
- testID="thread-navigation-sidebar"
132
- className="flex-1 border-border bg-drawer"
133
- style={{ borderRightWidth: StyleSheet.hairlineWidth, width: props.width }}
134
- >
135
- <StandaloneStack surface="sidebar" options={SIDEBAR_COLUMN_OPTIONS}>
136
- <ThreadNavigationSidebarPane {...props} nativeChrome />
137
- </StandaloneStack>
138
- </View>
139
- );
140
-}
141
-
142
-function ThreadNavigationSidebarPane(
143
- props: ThreadNavigationSidebarProps & { readonly nativeChrome: boolean },
144
-) {
112
+function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
113
const floatingTabsEnabled = useAndroidFloatingTabs();
114
const { themeVariables: materialTheme } = useAppearancePreferences();
115
const drawerColor = materialTheme["--color-drawer"];
120
const threads = useNavigationThreadShells();
121
const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
122
const { savedConnectionsById } = useSavedRemoteConnections();
155
- const searchBarRef = useRef<SearchBarCommands>(null);
123
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
124
const sidebarScrollGesture = useNativeGesture();
125
const {
302
},
303
]
304
: threadListV2Items;
338
- const listMenuActions = [
339
- {
340
- id: "environment",
341
- title: "Environment",
342
- subactions: [
343
- {
344
- id: "environment:all",
345
- title: "All environments",
346
- subtitle: "Show threads from every environment",
347
- state: options.selectedEnvironmentId === null ? "on" : "off",
348
- },
349
- ...environments.map((environment) => ({
350
- id: `environment:${environment.environmentId}`,
351
- title: environment.label,
352
- state:
353
- options.selectedEnvironmentId === environment.environmentId
354
- ? ("on" as const)
355
- : ("off" as const),
356
- })),
357
- ],
358
- },
359
- ...(projectFilterOptions.length === 0
360
- ? []
361
- : ([
362
- {
363
- id: "project",
364
- title: "Project",
365
- subactions: [
366
- {
367
- id: "project:all",
368
- title: "All projects",
369
- subtitle: "Show threads from every project",
370
- state: selectedProjectKey === null ? "on" : "off",
371
- },
372
- ...projectFilterOptions.map((project) => ({
373
- id: `project:${project.key}`,
374
- title: project.label,
375
- state: selectedProjectKey === project.key ? ("on" as const) : ("off" as const),
376
- })),
377
- ],
378
- },
379
- ] satisfies MenuAction[])),
380
- ] satisfies MenuAction[];
381
- const handleListMenuAction = ({
382
- nativeEvent,
383
- }: {
384
- readonly nativeEvent: { readonly event: string };
385
- }) => {
386
- const event = nativeEvent.event;
387
- if (event === "environment:all") {
388
- setSelectedEnvironmentId(null);
389
- return;
390
- }
391
- if (event.startsWith("environment:")) {
392
- const environment = environments.find(
393
- (candidate) => String(candidate.environmentId) === event.slice("environment:".length),
394
- );
395
- if (environment) setSelectedEnvironmentId(environment.environmentId);
396
- return;
397
- }
398
- if (event === "project:all") {
399
- setSelectedProjectKey(null);
400
- return;
401
- }
402
- if (event.startsWith("project:")) {
403
- const projectKey = event.slice("project:".length);
404
- if (projectFilterOptions.some((project) => project.key === projectKey)) {
405
- setSelectedProjectKey(projectKey);
406
- }
407
- return;
408
- }
409
- };
305
306
const handleSwipeableWillOpen = (methods: SwipeableMethods) => {
307
if (openSwipeableRef.current !== methods) {
365
}
366
return false;
367
};
473
- const focusSearch = () => {
474
- if (!props.nativeChrome) return false;
475
- const focus = () => searchBarRef.current?.focus();
476
- if (!props.visible) {
477
- props.onRequestVisibility();
478
- setTimeout(focus, 240);
479
- } else {
480
- focus();
481
- }
482
- return true;
483
- };
484
- useHardwareKeyboardCommand("focusSearch", focusSearch);
368
const renderListItem = ({ item }: { readonly item: SidebarListItem }) => {
369
switch (item.type) {
370
case "v2-pending": {
523
);
524
}
525
};
643
- const filterCustomized = options.selectedEnvironmentId !== null || selectedProjectKey !== null;
644
- const filterIcon = filterCustomized
645
- ? "line.3.horizontal.decrease.circle.fill"
646
- : "line.3.horizontal.decrease.circle";
647
- const filterMenu = buildHomeListFilterMenu({
648
- environments,
649
- projects: projectFilterOptions,
650
- selectedEnvironmentId: options.selectedEnvironmentId,
651
- selectedProjectKey,
652
- onEnvironmentChange: setSelectedEnvironmentId,
653
- onProjectChange: setSelectedProjectKey,
654
- });
655
- const nativeHeaderItems = createSidebarHeaderItems({
656
- filterIcon,
657
- filterMenu,
658
- onOpenSettings: props.onOpenSettings,
659
- });
526
+ const header = (
527
+ <WorkspaceListHeader
528
+ accessibilityLabel="T3 Code, Threads"
529
+ onOpenEnvironments={props.onOpenEnvironmentSettings}
530
+ onOpenSettings={props.onOpenSettings}
531
+ search={{
532
+ value: props.searchQuery,
533
+ onChangeText: props.onSearchQueryChange,
534
+ placeholder: "Search",
535
+ accessibilityLabel: "Search threads",
536
+ }}
537
+ filter={{
538
+ customized: options.selectedEnvironmentId !== null || selectedProjectKey !== null,
539
+ items: buildHomeListFilterMenuItems({
540
+ environments,
541
+ projects: projectFilterOptions,
542
+ selectedEnvironmentId: options.selectedEnvironmentId,
543
+ selectedProjectKey,
544
+ onEnvironmentChange: setSelectedEnvironmentId,
545
+ onProjectChange: setSelectedProjectKey,
546
+ }),
547
+ }}
548
+ sidebar={{
549
+ width: props.width,
550
+ visible: props.visible,
551
+ onRequestVisibility: props.onRequestVisibility,
552
+ }}
553
+ />
554
+ );
555
const listEmpty = (
556
<Text
557
className={
574
</Text>
575
);
576
682
- if (props.nativeChrome) {
577
+ if (Platform.OS === "ios") {
578
return (
579
<>
685
- <NativeStackScreenOptions
686
- optionsVersion={[nativeHeaderItems, props.width]}
687
- options={{
688
- ...getConnectionAwareBrandHeaderOptions({
689
- headerWidth: props.width,
690
- trailingItemCount: nativeHeaderItems.length,
691
- onOpenEnvironments: props.onOpenEnvironmentSettings,
692
- fallbackTitleStyle: { fontSize: 18, fontWeight: "800" },
693
- }),
694
- headerSearchBarOptions: {
695
- ref: searchBarRef,
696
- autoCapitalize: "none",
697
- hideNavigationBar: false,
698
- hideWhenScrolling: false,
699
- obscureBackground: false,
700
- placeholder: "Search",
701
- placement: "stacked",
702
- onCancelButtonPress: () => {
703
- props.onSearchQueryChange("");
704
- },
705
- onChangeText: (event) => {
706
- props.onSearchQueryChange(event.nativeEvent.text);
707
- },
708
- },
709
- unstable_headerRightItems: () => nativeHeaderItems,
710
- }}
711
- />
580
+ {header}
581
<View className="flex-1">
582
<SwipeableScrollGateProvider enabled={swipeEnabled}>
583
<GestureDetector gesture={sidebarScrollGesture}>
592
itemsAreEqual={sidebarItemsAreEqual}
593
keyExtractor={(item) => item.key}
594
renderItem={renderListItem}
726
- automaticallyAdjustsScrollIndicatorInsets={NATIVE_LIQUID_GLASS_SUPPORTED}
727
- contentInsetAdjustmentBehavior={
728
- NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never"
729
- }
595
+ {...WORKSPACE_LIST_SCROLL_INSETS}
596
contentContainerStyle={[
597
styles.threadListContent,
598
{
617
);
618
}
619
754
- // Android: the bar is the floating ThreadListToolbar below the list.
620
+ // Android: the bar floats below the list.
621
return (
622
<View testID="thread-navigation-sidebar" className="flex-1 bg-header">
623
<View
666
</SwipeableScrollGateProvider>
667
)}
668
</View>
803
- <ThreadListToolbar
804
- searchQuery={props.searchQuery}
805
- onSearchQueryChange={props.onSearchQueryChange}
806
- filterActions={listMenuActions}
807
- filterCustomized={filterCustomized}
808
- onFilterSelect={(event) => handleListMenuAction({ nativeEvent: { event } })}
809
- onOpenEnvironments={props.onOpenEnvironmentSettings}
810
- onRequestVisibility={props.onRequestVisibility}
811
- />
669
+ {header}
670
<ThreadUndoNotice visible={props.visible} />
671
</View>
672
);