The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 108 lines 4.13 KB
Raw
1 import { StackActions, useNavigation } from "@react-navigation/native";
2 import { T, useGT, useMessages, Var } from "gt-react-native";
3 import { useState } from "react";
4 import { View } from "react-native";
5 import { AppText as Text } from "../../components/ui/AppText";
6 import { PullRequestCardGroup, PullRequestCardRow } from "./PullRequestControls";
7 import { pullRequestLayerParams } from "./pullRequestStack";
8 import { pullRequestStatus } from "./pullRequestStatus";
9 import type { PullRequestParams } from "./usePullRequestDiff";
10 import type { PullRequestStackState } from "./usePullRequestStack";
11 import { PullRequestGlyph } from "./pullRequestGlyphs";
12 import { withKnownPullRequestSummary } from "../../state/use-thread-pr";
13
14 export function PullRequestStackCard(props: {
15 readonly params: PullRequestParams;
16 readonly state: PullRequestStackState;
17 }) {
18 const navigation = useNavigation();
19 const gt = useGT();
20 const m = useMessages();
21 const [expanded, setExpanded] = useState(false);
22 const stack = props.state.stack;
23 if (!stack) {
24 const summary =
25 props.params.initialSummary?.number === props.params.number
26 ? props.params.initialSummary.stack
27 : undefined;
28 if (!summary) return null;
29 return (
30 <PullRequestCardGroup>
31 <PullRequestCardRow
32 title={gt("Stack", { $context: "stacked pull requests" })}
33 icon={PullRequestGlyph.stack}
34 value={gt("{position} of {total}", { position: summary.position, total: summary.size })}
35 last
36 />
37 </PullRequestCardGroup>
38 );
39 }
40 const position = stack.layers.findIndex((layer) => layer.number === props.params.number) + 1;
41 return (
42 <PullRequestCardGroup>
43 <PullRequestCardRow
44 title={gt("Stack", { $context: "stacked pull requests" })}
45 icon={PullRequestGlyph.stack}
46 value={gt("{position} of {total}", { position, total: stack.layers.length })}
47 accessibilityLabel={
48 props.state.isFresh
49 ? gt("Stack, {position} of {total}", { position, total: stack.layers.length })
50 : gt("Stack, {position} of {total}, showing saved stack", {
51 position,
52 total: stack.layers.length,
53 })
54 }
55 expanded={expanded}
56 onPress={() => setExpanded(!expanded)}
57 last={!expanded}
58 />
59 {expanded ? (
60 <View>
61 {stack.layers.map((layer, index) => {
62 const selected = layer.number === props.params.number;
63 const status = pullRequestStatus(
64 { state: layer.state, isDraft: layer.isDraft === true },
65 m,
66 );
67 return (
68 <View key={layer.number} className={selected ? "bg-thread-selected" : undefined}>
69 <PullRequestCardRow
70 title={layer.title ?? layer.headBranch}
71 icon={status.icon}
72 tint={status.tint}
73 value={
74 selected ? gt("Current", { $context: "current stack layer" }) : status.label
75 }
76 detail={`#${layer.number} · ${gt("{position} of {total}", {
77 position: index + 1,
78 total: stack.layers.length,
79 })}`}
80 onPress={
81 selected
82 ? undefined
83 : () =>
84 navigation.dispatch(
85 StackActions.push(
86 "PullRequest",
87 withKnownPullRequestSummary(
88 pullRequestLayerParams(props.params, layer.number),
89 ),
90 ),
91 )
92 }
93 last={index === stack.layers.length - 1}
94 />
95 </View>
96 );
97 })}
98 <Text className="px-4 py-3 text-xs text-foreground-muted">
99 <T>
100 Base: <Var>{stack.base}</Var>. Open a layer to review it or merge the stack through
101 that layer.
102 </T>
103 </Text>
104 </View>
105 ) : null}
106 </PullRequestCardGroup>
107 );
108 }