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-row items-center justify-center gap-2 px-4 py-3 disabled:opacity-[0.45]",
40 "flex-1 rounded-[18px]",
41 tone === "primary" ? "bg-primary" : tone === "danger" ? "bg-danger" : "bg-secondary",
42 tone !== "primary" &&
43 (tone === "danger" ? "border border-danger-border" : "border border-secondary-border"),
44 )}
45 accessibilityRole="button"
46 disabled={props.disabled}
47 onPress={props.onPress}
48 >
49 <SymbolView
50 name={props.icon}
51 size={16}
52 tintColorClassName={textColorClassName}
53 type="monochrome"
54 />
55 <Text
56 className={cn(
57 "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 </Pressable>
68 );
69}
70
71export function MetaCard(props: { readonly label: string; readonly value: string }) {
72 return (
73 <View className="bg-card px-4 py-3 android:rounded-[20px] ios:rounded-[18px] ios:border ios:border-border">
74 <Text className="text-foreground-muted text-2xs font-t3-bold tracking-[0.9px] uppercase">
75 {props.label}
76 </Text>
77 <Text selectable className="text-foreground text-sm font-medium" numberOfLines={1}>
78 {props.value}
79 </Text>
80 </View>
81 );
82}
83
84export function SheetListRow(props: {
85 readonly icon: ComponentProps<typeof SymbolView>["name"];
86 readonly title: string;
87 readonly subtitle?: string | null;
88 readonly disabled?: boolean;
89 readonly onPress: () => void;
90}) {
91 return (
92 <Pressable
93 className="flex-row items-center py-3 disabled:opacity-[0.45] android:min-h-16 android:gap-4 android:px-4 android:active:bg-subtle ios:gap-3 ios:px-1"
94 disabled={props.disabled}
95 onPress={props.onPress}
96 >
97 <View className="items-center justify-center android:size-6 ios:bg-subtle ios:h-9 ios:w-9 ios:rounded-full">
98 <SymbolView
99 name={props.icon}
100 size={Platform.OS === "android" ? 24 : 16}
101 tintColorClassName="accent-icon"
102 type="monochrome"
103 />
104 </View>
105 <View className="flex-1 gap-0.5">
106 <Text className="text-foreground text-base android:font-t3-medium ios:font-t3-bold">
107 {props.title}
108 </Text>
109 {props.subtitle ? (
110 <Text className="text-foreground-muted text-xs leading-snug">{props.subtitle}</Text>
111 ) : null}
112 </View>
113 {Platform.OS !== "android" ? (
114 <SymbolView
115 name="chevron.right"
116 size={13}
117 tintColorClassName="accent-icon-subtle"
118 type="monochrome"
119 />
120 ) : null}
121 </Pressable>
122 );
123}
124
125export function menuItemIconName(
126 icon: "commit" | "push" | "pr",
127): ComponentProps<typeof SymbolView>["name"] {
128 if (icon === "commit") return "checkmark.circle";
129 if (icon === "push") return "arrow.up.circle";
130 return "arrow.up.right.circle";
131}
132
133export function statusSummary(
134 gitStatus: {
135 readonly isRepo?: boolean;
136 readonly hasWorkingTreeChanges?: boolean;
137 readonly workingTree?: { readonly files: readonly { readonly path: string }[] };
138 readonly aheadCount?: number;
139 readonly behindCount?: number;
140 readonly pr?: { readonly state?: string; readonly number?: number } | null;
141 } | null,
142): string {
143 if (!gitStatus) {
144 return "Loading branch status\u2026";
145 }
146
147 if (!gitStatus.isRepo) {
148 return "Not a git repository";
149 }
150
151 const parts: string[] = [];
152 if (gitStatus.hasWorkingTreeChanges) {
153 const fileCount = gitStatus.workingTree?.files.length ?? 0;
154 parts.push(`${fileCount} file${fileCount === 1 ? "" : "s"} changed`);
155 } else {
156 parts.push("Clean");
157 }
158 if ((gitStatus.aheadCount ?? 0) > 0) {
159 parts.push(`${gitStatus.aheadCount} ahead`);
160 }
161 if ((gitStatus.behindCount ?? 0) > 0) {
162 parts.push(`${gitStatus.behindCount} behind`);
163 }
164 if (gitStatus.pr?.state === "open") {
165 parts.push(`PR #${gitStatus.pr.number} open`);
166 }
167
168 return parts.join(" \u00b7 ");
169}