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

gitSheetComponents.tsx

143 lines4.9 KB

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