Open History to see the last commit
1import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
2import type { ChangeRequestTerminology } from "@t3tools/client-runtime/source-control-clients";
3import type { PullRequestActor } from "@t3tools/contracts";
4import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
5import { Image } from "expo-image";
6import { useGT, select } from "gt-react-native";
7import { View } from "react-native";
8import { useResolveClassNames } from "uniwind";
9
10import { AppText as Text } from "../../components/ui/AppText";
11import { cn } from "../../lib/cn";
12import { changeRequestTermKind } from "../../lib/changeRequestTerm";
13import { EmptyState } from "../../components/ui/EmptyState";
14
15export function PullRequestReadStatus(props: {
16 readonly pending: boolean;
17 readonly error: string | null;
18 readonly terminology: ChangeRequestTerminology;
19}) {
20 const gt = useGT();
21 return props.pending ? (
22 <AppActivityIndicator className="my-12" colorClassName="accent-icon" />
23 ) : props.error ? (
24 <EmptyState
25 title={gt`Couldn't load this ${select(
26 { term: changeRequestTermKind(props.terminology) },
27 {
28 mr: "merge request",
29 cr: "change request",
30 other: "pull request",
31 },
32 )}`}
33 detail={props.error}
34 variant="plain"
35 />
36 ) : null;
37}
38
39export function PullRequestConflictBadge(props: { readonly surfaceClassName: string }) {
40 const { color } = useResolveClassNames("text-danger-foreground");
41 const { color: surface } = useResolveClassNames(props.surfaceClassName);
42 return (
43 <View pointerEvents="none" className="absolute -right-1 -bottom-1">
44 <IconAlertTriangle size={15} strokeWidth={2.5} color={surface} fill={surface} />
45 <View className="absolute inset-0">
46 <IconAlertTriangle size={15} strokeWidth={2.5} color={color} />
47 </View>
48 </View>
49 );
50}
51
52export function PullRequestAvatar(props: {
53 readonly actor: PullRequestActor | null;
54 readonly size?: number;
55}) {
56 const size = props.size ?? 24;
57 return props.actor?.avatarUrl ? (
58 <Image
59 source={{ uri: props.actor.avatarUrl }}
60 recyclingKey={props.actor.avatarUrl}
61 accessibilityLabel={props.actor.login}
62 style={{ width: size, height: size, borderRadius: size / 2 }}
63 cachePolicy="memory-disk"
64 />
65 ) : (
66 <View
67 className="items-center justify-center rounded-full bg-grouped-card"
68 style={{ width: size, height: size }}
69 >
70 <Text className="font-t3-medium text-foreground-muted" style={{ fontSize: size * 0.45 }}>
71 {props.actor ? [...props.actor.login][0]?.toUpperCase() : "?"}
72 </Text>
73 </View>
74 );
75}
76
77export function PullRequestDiffStats(props: {
78 readonly additions: number;
79 readonly deletions: number;
80 readonly compact?: boolean;
81}) {
82 const textSize = props.compact ? "text-2xs" : "text-xs";
83 return (
84 <View className="shrink-0 flex-row items-center gap-2">
85 {!props.compact || props.additions > 0 ? (
86 <Text className={cn(textSize, "font-t3-medium tabular-nums text-adaptive-emerald-600-400")}>
87 +{props.additions.toLocaleString()}
88 </Text>
89 ) : null}
90 {!props.compact || props.deletions > 0 ? (
91 <Text className={cn(textSize, "font-t3-medium tabular-nums text-danger-foreground")}>
92 −{props.deletions.toLocaleString()}
93 </Text>
94 ) : null}
95 </View>
96 );
97}