Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

gitSheetComponents.tsx

173 lines5.5 KB

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