Open History to see the last commit
1import { StackActions, useNavigation } from "@react-navigation/native";
2import { T, useGT, useMessages, Var } from "gt-react-native";
3import { useState } from "react";
4import { View } from "react-native";
5import { AppText as Text } from "../../components/ui/AppText";
6import { PullRequestCardGroup, PullRequestCardRow } from "./PullRequestControls";
7import { pullRequestLayerParams } from "./pullRequestStack";
8import { pullRequestStatus } from "./pullRequestStatus";
9import type { PullRequestParams } from "./usePullRequestDiff";
10import type { PullRequestStackState } from "./usePullRequestStack";
11import { PullRequestGlyph } from "./pullRequestGlyphs";
12import { withKnownPullRequestSummary } from "../../state/use-thread-pr";
13
14export 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({ context: "stacked pull requests" })`Stack`}
33 icon={PullRequestGlyph.stack}
34 value={gt`${{ position: summary.position }} of ${{ 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({ context: "stacked pull requests" })`Stack`}
45 icon={PullRequestGlyph.stack}
46 value={gt`${{ position }} of ${{ total: stack.layers.length }}`}
47 accessibilityLabel={
48 props.state.isFresh
49 ? gt`Stack, ${{ position }} of ${{ total: stack.layers.length }}`
50 : gt`Stack, ${{ position }} of ${{ total: stack.layers.length }}, showing saved stack`
51 }
52 expanded={expanded}
53 onPress={() => setExpanded(!expanded)}
54 last={!expanded}
55 />
56 {expanded ? (
57 <View>
58 {stack.layers.map((layer, index) => {
59 const selected = layer.number === props.params.number;
60 const status = pullRequestStatus(
61 { state: layer.state, isDraft: layer.isDraft === true },
62 m,
63 );
64 return (
65 <View key={layer.number} className={selected ? "bg-thread-selected" : undefined}>
66 <PullRequestCardRow
67 title={layer.title ?? layer.headBranch}
68 icon={status.icon}
69 tint={status.tint}
70 value={selected ? gt({ context: "current stack layer" })`Current` : status.label}
71 detail={`#${layer.number} · ${gt`${{ position: index + 1 }} of ${{ total: stack.layers.length }}`}`}
72 onPress={
73 selected
74 ? undefined
75 : () =>
76 navigation.dispatch(
77 StackActions.push(
78 "PullRequest",
79 withKnownPullRequestSummary(
80 pullRequestLayerParams(props.params, layer.number),
81 ),
82 ),
83 )
84 }
85 last={index === stack.layers.length - 1}
86 />
87 </View>
88 );
89 })}
90 <Text className="px-4 py-3 text-xs text-foreground-muted">
91 <T>
92 Base: <Var>{stack.base}</Var>. Open a layer to review it or merge the stack through
93 that layer.
94 </T>
95 </Text>
96 </View>
97 ) : null}
98 </PullRequestCardGroup>
99 );
100}