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