Open History to see the last commit
1import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
2import { LegendList } from "@legendapp/list/react-native";
3import { useMemo } from "react";
4import { Platform, View } from "react-native";
5import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7import { AndroidSheetHeader } from "../../components/ui/AndroidScreenHeader";
8import { AppText as Text } from "../../components/ui/AppText";
9import { ScreenContent } from "../../components/ui/ScreenContent";
10import { SheetHeader } from "../../components/ui/SheetHeader";
11import { Toolbar } from "../../components/ui/Toolbar";
12import { NativeStackScreenOptions } from "../../native/StackHeader";
13import { useOpenPullRequest } from "../../native/useOpenPullRequest";
14import { useThreadSelection } from "../../state/use-thread-selection";
15import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
16import {
17 LinkedPullRequestRow,
18 linkedPullRequestKey,
19 useLinkedPullRequestLines,
20} from "./LinkedPullRequestList";
21import { useLinkedPullRequestActions } from "./useLinkedPullRequestActions";
22
23export function ThreadPullRequestsSheet(
24 _props: StaticScreenProps<{ readonly environmentId: string; readonly threadId: string }>,
25) {
26 const { layout } = useAdaptiveWorkspaceLayout();
27 const navigation = useNavigation();
28 const insets = useSafeAreaInsets();
29 const { selectedThread, selectedThreadProject, selectedEnvironmentRuntime } =
30 useThreadSelection();
31 const lines = useLinkedPullRequestLines(selectedThread, selectedEnvironmentRuntime);
32 const openCount = useMemo(
33 () =>
34 lines.filter((line) => line.link.snapshot === null || line.link.snapshot.state === "open")
35 .length,
36 [lines],
37 );
38 const openPullRequest = useOpenPullRequest({
39 replace: true,
40 context: selectedThread ?? undefined,
41 });
42 const actions = useLinkedPullRequestActions({
43 thread: selectedThread,
44 project: selectedThreadProject,
45 runtime: selectedEnvironmentRuntime,
46 });
47 const rowInputs = { lines, actions };
48 const { singular } = actions.terminology;
49 const title = `Linked ${actions.terminology.plural}`;
50
51 const content = (
52 <View className="flex-1 android:bg-sheet-solid ios:bg-screen">
53 {/* oxlint-disable-next-line t3code/require-registered-list-scroll -- Sheet content; sheets sit outside workspace columns and keep their own header handling. */}
54 <LegendList
55 data={lines}
56 keyExtractor={linkedPullRequestKey}
57 extraData={rowInputs}
58 renderItem={({ item, index }) => (
59 <LinkedPullRequestRow
60 line={item}
61 separator={index < lines.length - 1}
62 surfaceClassName={Platform.OS === "ios" ? "text-screen" : "text-sheet-solid"}
63 openPullRequest={openPullRequest}
64 actions={actions}
65 />
66 )}
67 estimatedItemSize={88}
68 recycleItems
69 alwaysBounceVertical
70 style={{ flex: 1 }}
71 contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
72 showsVerticalScrollIndicator={false}
73 contentContainerStyle={{
74 paddingBottom: Math.max(insets.bottom, 18) + 18,
75 paddingHorizontal: 8,
76 }}
77 ListHeaderComponent={
78 lines.length > 0 ? (
79 <Text className="px-4 pt-2 pb-1 text-xs text-foreground-muted">
80 {openCount} open · {lines.length} linked
81 </Text>
82 ) : null
83 }
84 ListEmptyComponent={
85 <Text className="pt-6 text-center text-sm text-foreground-muted">
86 No linked {actions.terminology.plural}.
87 </Text>
88 }
89 />
90 </View>
91 );
92
93 if (Platform.OS === "ios") {
94 return (
95 <View collapsable={false} className="flex-1 bg-sheet">
96 <SheetHeader presentation="native" title={title} onClose={() => navigation.goBack()} />
97 {actions.canLink ? (
98 <Toolbar placement="right">
99 <Toolbar.Button
100 icon="plus"
101 accessibilityLabel={`Link ${singular}`}
102 onPress={actions.promptLink}
103 />
104 </Toolbar>
105 ) : null}
106 {content}
107 </View>
108 );
109 }
110
111 return (
112 <View collapsable={false} className="flex-1 bg-header">
113 <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
114 <AndroidSheetHeader
115 title={title}
116 hideBottomBorder
117 onBack={() => navigation.goBack()}
118 actions={
119 actions.canLink
120 ? [
121 {
122 accessibilityLabel: `Link ${singular}`,
123 icon: "plus",
124 onPress: actions.promptLink,
125 },
126 ]
127 : undefined
128 }
129 />
130 <ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
131 </View>
132 );
133}