Open History to see the last commit
1import { SymbolView } from "../../../components/AppSymbol";
2import type { ComponentProps } from "react";
3import { Pressable, View } from "react-native";
4import { AppText as Text } from "../../../components/AppText";
5import { cn } from "../../../lib/cn";
6
7/* ─── Shared sheet components ──────────────────────────────────────── */
8
9export function SheetActionButton(props: {
10 readonly icon: ComponentProps<typeof SymbolView>["name"];
11 readonly label: string;
12 readonly disabled?: boolean;
13 readonly tone?: "primary" | "secondary" | "danger";
14 readonly onPress: () => void;
15}) {
16 const tone = props.tone ?? "secondary";
17 const textColorClassName =
18 tone === "primary"
19 ? "accent-primary-foreground"
20 : tone === "danger"
21 ? "accent-danger-foreground"
22 : "accent-secondary-foreground";
23
24 return (
25 <Pressable
26 className={cn(
27 "min-h-[48px] flex-1 flex-row items-center justify-center gap-2 rounded-[18px] px-4 py-3 disabled:opacity-[0.45]",
28 tone === "primary"
29 ? "bg-primary"
30 : tone === "danger"
31 ? "border border-danger-border bg-danger"
32 : "border border-secondary-border bg-secondary",
33 )}
34 disabled={props.disabled}
35 onPress={props.onPress}
36 >
37 <SymbolView
38 name={props.icon}
39 size={16}
40 tintColorClassName={textColorClassName}
41 type="monochrome"
42 />
43 <Text
44 className={cn(
45 "text-xs font-t3-bold tracking-[0.9px] uppercase",
46 tone === "primary"
47 ? "text-primary-foreground"
48 : tone === "danger"
49 ? "text-danger-foreground"
50 : "text-secondary-foreground",
51 )}
52 >
53 {props.label}
54 </Text>
55 </Pressable>
56 );
57}
58
59export function MetaCard(props: { readonly label: string; readonly value: string }) {
60 return (
61 <View className="rounded-[18px] border border-border bg-card px-4 py-3">
62 <Text className="text-foreground-muted text-2xs font-t3-bold tracking-[0.9px] uppercase">
63 {props.label}
64 </Text>
65 <Text selectable className="text-foreground text-sm font-medium" numberOfLines={1}>
66 {props.value}
67 </Text>
68 </View>
69 );
70}
71
72export function SheetListRow(props: {
73 readonly icon: ComponentProps<typeof SymbolView>["name"];
74 readonly title: string;
75 readonly subtitle?: string | null;
76 readonly disabled?: boolean;
77 readonly onPress: () => void;
78}) {
79 return (
80 <Pressable
81 className="flex-row items-center gap-3 px-1 py-3 disabled:opacity-[0.45]"
82 disabled={props.disabled}
83 onPress={props.onPress}
84 >
85 <View className="bg-subtle h-9 w-9 items-center justify-center rounded-full">
86 <SymbolView
87 name={props.icon}
88 size={16}
89 tintColorClassName={"accent-icon"}
90 type="monochrome"
91 />
92 </View>
93 <View className="flex-1 gap-0.5">
94 <Text className="text-foreground text-base font-t3-bold">{props.title}</Text>
95 {props.subtitle ? (
96 <Text className="text-foreground-muted text-xs leading-snug">{props.subtitle}</Text>
97 ) : null}
98 </View>
99 <SymbolView
100 name="chevron.right"
101 size={13}
102 tintColorClassName={"accent-icon-subtle"}
103 type="monochrome"
104 />
105 </Pressable>
106 );
107}
108
109/* ─── Shared utilities ──────────────────────────────────────────────── */
110
111export function menuItemIconName(
112 icon: "commit" | "push" | "pr",
113): ComponentProps<typeof SymbolView>["name"] {
114 if (icon === "commit") return "checkmark.circle";
115 if (icon === "push") return "arrow.up.circle";
116 return "arrow.up.right.circle";
117}
118
119export function statusSummary(
120 gitStatus: {
121 readonly isRepo?: boolean;
122 readonly hasWorkingTreeChanges?: boolean;
123 readonly workingTree?: { readonly files: readonly { readonly path: string }[] };
124 readonly aheadCount?: number;
125 readonly behindCount?: number;
126 readonly pr?: { readonly state?: string; readonly number?: number } | null;
127 } | null,
128): string {
129 if (!gitStatus) {
130 return "Loading branch status\u2026";
131 }
132
133 if (!gitStatus.isRepo) {
134 return "Not a git repository";
135 }
136
137 const parts: string[] = [];
138 if (gitStatus.hasWorkingTreeChanges) {
139 const fileCount = gitStatus.workingTree?.files.length ?? 0;
140 parts.push(`${fileCount} file${fileCount === 1 ? "" : "s"} changed`);
141 } else {
142 parts.push("Clean");
143 }
144 if ((gitStatus.aheadCount ?? 0) > 0) {
145 parts.push(`${gitStatus.aheadCount} ahead`);
146 }
147 if ((gitStatus.behindCount ?? 0) > 0) {
148 parts.push(`${gitStatus.behindCount} behind`);
149 }
150 if (gitStatus.pr?.state === "open") {
151 parts.push(`PR #${gitStatus.pr.number} open`);
152 }
153
154 return parts.join(" \u00b7 ");
155}