The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useNavigation, type StaticScreenProps } from "@react-navigation/native"; |
| 2 | import { LegendList } from "@legendapp/list/react-native"; |
| 3 | import { useGT } from "gt-react-native"; |
| 4 | import { changeRequestTermKind } from "../../lib/changeRequestTerm"; |
| 5 | import { useMemo } from "react"; |
| 6 | import { View } from "react-native"; |
| 7 | import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 8 | |
| 9 | import { AppText as Text } from "../../components/ui/AppText"; |
| 10 | import { ScreenContent } from "../../components/ui/ScreenContent"; |
| 11 | import { SheetHeader } from "../../components/ui/SheetHeader"; |
| 12 | import { useOpenPullRequest } from "../../native/useOpenPullRequest"; |
| 13 | import { useThreadSelection } from "../../state/use-thread-selection"; |
| 14 | import { |
| 15 | LinkedPullRequestRow, |
| 16 | linkedPullRequestKey, |
| 17 | useLinkedPullRequestLines, |
| 18 | } from "./LinkedPullRequestList"; |
| 19 | import { useLinkedPullRequestActions } from "./useLinkedPullRequestActions"; |
| 20 | |
| 21 | export function ThreadPullRequestsSheet( |
| 22 | _props: StaticScreenProps<{ readonly environmentId: string; readonly threadId: string }>, |
| 23 | ) { |
| 24 | const navigation = useNavigation(); |
| 25 | const gt = useGT(); |
| 26 | const insets = useSafeAreaInsets(); |
| 27 | const { selectedThread, selectedThreadProject, selectedEnvironmentRuntime } = |
| 28 | useThreadSelection(); |
| 29 | const lines = useLinkedPullRequestLines(selectedThread, selectedEnvironmentRuntime); |
| 30 | const openCount = useMemo( |
| 31 | () => |
| 32 | lines.filter((line) => line.link.snapshot === null || line.link.snapshot.state === "open") |
| 33 | .length, |
| 34 | [lines], |
| 35 | ); |
| 36 | const openPullRequest = useOpenPullRequest({ |
| 37 | replace: true, |
| 38 | context: selectedThread ?? undefined, |
| 39 | }); |
| 40 | const actions = useLinkedPullRequestActions({ |
| 41 | thread: selectedThread, |
| 42 | project: selectedThreadProject, |
| 43 | runtime: selectedEnvironmentRuntime, |
| 44 | }); |
| 45 | const rowInputs = { lines, actions }; |
| 46 | const term = changeRequestTermKind(actions.terminology); |
| 47 | const title = gt( |
| 48 | "{term, select, mr {Linked merge requests} cr {Linked change requests} other {Linked pull requests}}", |
| 49 | { term }, |
| 50 | ); |
| 51 | |
| 52 | const content = ( |
| 53 | <View className="flex-1 bg-screen"> |
| 54 | {/* oxlint-disable-next-line t3code/require-registered-list-scroll -- Sheet content; sheets sit outside workspace columns and keep their own header handling. */} |
| 55 | <LegendList |
| 56 | data={lines} |
| 57 | keyExtractor={linkedPullRequestKey} |
| 58 | extraData={rowInputs} |
| 59 | renderItem={({ item, index }) => ( |
| 60 | <LinkedPullRequestRow |
| 61 | line={item} |
| 62 | separator={index < lines.length - 1} |
| 63 | surfaceClassName="text-screen" |
| 64 | openPullRequest={openPullRequest} |
| 65 | actions={actions} |
| 66 | /> |
| 67 | )} |
| 68 | estimatedItemSize={88} |
| 69 | recycleItems |
| 70 | alwaysBounceVertical |
| 71 | style={{ flex: 1 }} |
| 72 | contentInsetAdjustmentBehavior="automatic" |
| 73 | showsVerticalScrollIndicator={false} |
| 74 | contentContainerStyle={{ |
| 75 | paddingBottom: Math.max(insets.bottom, 18) + 18, |
| 76 | paddingHorizontal: 8, |
| 77 | }} |
| 78 | ListHeaderComponent={ |
| 79 | lines.length > 0 ? ( |
| 80 | <Text className="px-4 pt-2 pb-1 text-xs text-foreground-muted"> |
| 81 | {gt("{open} open · {linked} linked", { open: openCount, linked: lines.length })} |
| 82 | </Text> |
| 83 | ) : null |
| 84 | } |
| 85 | ListEmptyComponent={ |
| 86 | <Text className="pt-6 text-center text-sm text-foreground-muted"> |
| 87 | {gt( |
| 88 | "{term, select, mr {No linked merge requests.} cr {No linked change requests.} other {No linked pull requests.}}", |
| 89 | { term }, |
| 90 | )} |
| 91 | </Text> |
| 92 | } |
| 93 | /> |
| 94 | </View> |
| 95 | ); |
| 96 | |
| 97 | return ( |
| 98 | <View collapsable={false} className="flex-1 bg-sheet"> |
| 99 | <SheetHeader |
| 100 | title={title} |
| 101 | onClose={() => navigation.goBack()} |
| 102 | actions={ |
| 103 | actions.canLink |
| 104 | ? [ |
| 105 | { |
| 106 | accessibilityLabel: gt( |
| 107 | "{term, select, mr {Link merge request} cr {Link change request} other {Link pull request}}", |
| 108 | { term }, |
| 109 | ), |
| 110 | icon: "plus", |
| 111 | onPress: actions.promptLink, |
| 112 | }, |
| 113 | ] |
| 114 | : undefined |
| 115 | } |
| 116 | /> |
| 117 | <ScreenContent>{content}</ScreenContent> |
| 118 | </View> |
| 119 | ); |
| 120 | } |