Open History to see the last commit
1import { SymbolView } from "../../../components/ui/AppSymbol";
2import type { ComponentProps } from "react";
3import { Platform, Pressable, View } from "react-native";
4import { AppText as Text } from "../../../components/ui/AppText";
5import { Button } from "../../../components/ui/Button";
6import { cn } from "../../../lib/cn";
7
8export function SheetActionButton(props: {
9 readonly icon: ComponentProps<typeof SymbolView>["name"];
10 readonly label: string;
11 readonly disabled?: boolean;
12 readonly tone?: "primary" | "secondary" | "danger";
13 readonly onPress: () => void;
14}) {
15 if (Platform.OS === "android")
16 return (
17 <View className="flex-1">
18 <Button
19 label={props.label}
20 icon={props.icon}
21 tone={props.tone}
22 disabled={props.disabled}
23 onPress={props.onPress}
24 fullWidth
25 />
26 </View>
27 );
28 const tone = props.tone ?? "secondary";
29 const textColorClassName =
30 tone === "primary"
31 ? "accent-primary-foreground"
32 : tone === "danger"
33 ? "accent-danger-foreground"
34 : "accent-secondary-foreground";
35
36 return (
37 <Pressable
38 className={cn(
39 "min-h-[48px] flex-1 items-center justify-center rounded-[18px] px-3 py-3 disabled:opacity-[0.45]",
40 tone === "primary" ? "bg-primary" : tone === "danger" ? "bg-danger" : "bg-secondary",
41 tone !== "primary" &&
42 (tone === "danger" ? "border border-danger-border" : "border border-secondary-border"),
43 )}
44 accessibilityRole="button"
45 disabled={props.disabled}
46 onPress={props.onPress}
47 >
48 <View className="max-w-full flex-row items-center justify-center gap-1.5">
49 <SymbolView
50 name={props.icon}
51 size={16}
52 tintColorClassName={textColorClassName}
53 type="monochrome"
54 />
55 <Text
56 className={cn(
57 "shrink text-center text-xs font-t3-bold tracking-[0.9px] uppercase",
58 tone === "primary"
59 ? "text-primary-foreground"
60 : tone === "danger"
61 ? "text-danger-foreground"
62 : "text-secondary-foreground",
63 )}
64 >
65 {props.label}
66 </Text>
67 </View>
68 </Pressable>
69 );
70}
71
72export function menuItemIconName(
73 icon: "commit" | "push" | "pr",
74): ComponentProps<typeof SymbolView>["name"] {
75 if (icon === "commit") return "checkmark.circle";
76 if (icon === "push") return "arrow.up.circle";
77 return "arrow.up.right.circle";
78}
79
80export function statusSummary(
81 gitStatus: {
82 readonly isRepo?: boolean;
83 readonly hasWorkingTreeChanges?: boolean;
84 readonly workingTree?: { readonly files: readonly { readonly path: string }[] };
85 readonly aheadCount?: number;
86 readonly behindCount?: number;
87 readonly pr?: { readonly state?: string; readonly number?: number } | null;
88 } | null,
89): string {
90 if (!gitStatus) {
91 return "Loading branch status\u2026";
92 }
93
94 if (!gitStatus.isRepo) {
95 return "Not a git repository";
96 }
97
98 const parts: string[] = [];
99 if (gitStatus.hasWorkingTreeChanges) {
100 const fileCount = gitStatus.workingTree?.files.length ?? 0;
101 parts.push(`${fileCount} file${fileCount === 1 ? "" : "s"} changed`);
102 } else {
103 parts.push("Clean");
104 }
105 if ((gitStatus.aheadCount ?? 0) > 0) {
106 parts.push(`${gitStatus.aheadCount} ahead`);
107 }
108 if ((gitStatus.behindCount ?? 0) > 0) {
109 parts.push(`${gitStatus.behindCount} behind`);
110 }
111 if (gitStatus.pr?.state === "open") {
112 parts.push(`PR #${gitStatus.pr.number} open`);
113 }
114
115 return parts.join(" \u00b7 ");
116}