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

gitSheetComponents.tsx

161 lines5.4 KB

1import { SymbolView } from "expo-symbols";
2import type { ComponentProps } from "react";
3import { Pressable, View } from "react-native";
4import { useThemeColor } from "../../../lib/useThemeColor";
5import { AppText as Text } from "../../../components/AppText";
6​
7/* ─── Shared sheet components ──────────────────────────────────────── */
8​
9export function SheetActionButton(props: {
10 readonly icon: ComponentProps<typeof SymbolView>["name"];
11 readonly label: string;
12 readonly disabled?: boolean;
13 readonly tone?: "primary" | "secondary" | "danger";
14 readonly onPress: () => void;
15}) {
16 const primaryBg = useThemeColor("--color-primary");
17 const primaryFg = useThemeColor("--color-primary-foreground");
18 const dangerBg = useThemeColor("--color-danger");
19 const dangerBorder = useThemeColor("--color-danger-border");
20 const dangerFg = useThemeColor("--color-danger-foreground");
21 const secondaryBg = useThemeColor("--color-secondary");
22 const secondaryBorder = useThemeColor("--color-secondary-border");
23 const secondaryFg = useThemeColor("--color-secondary-foreground");
24​
25 const tone = props.tone ?? "secondary";
26 const colors =
27 tone === "primary"
28 ? {
29 backgroundColor: primaryBg,
30 borderColor: "transparent",
31 textColor: primaryFg,
32 }
33 : tone === "danger"
34 ? {
35 backgroundColor: dangerBg,
36 borderColor: dangerBorder,
37 textColor: dangerFg,
38 }
39 : {
40 backgroundColor: secondaryBg,
41 borderColor: secondaryBorder,
42 textColor: secondaryFg,
43 };
44​
45 return (
46 <Pressable
47 className="min-h-[48px] flex-1 flex-row items-center justify-center gap-2 rounded-[18px] px-4 py-3"
48 disabled={props.disabled}
49 style={{
50 backgroundColor: colors.backgroundColor,
51 borderWidth: tone === "primary" ? 0 : 1,
52 borderColor: colors.borderColor,
53 opacity: props.disabled ? 0.45 : 1,
54 }}
55 onPress={props.onPress}
56 >
57 <SymbolView name={props.icon} size={16} tintColor={colors.textColor} type="monochrome" />
58 <Text
59 className="text-[12px] font-t3-bold uppercase"
60 style={{ color: colors.textColor, letterSpacing: 0.9 }}
61 >
62 {props.label}
63 </Text>
64 </Pressable>
65 );
67​
68export function MetaCard(props: { readonly label: string; readonly value: string }) {
69 return (
70 <View className="rounded-[18px] border border-border bg-card px-4 py-3">
71 <Text
72 className="text-foreground-muted text-[11px] font-t3-bold uppercase"
73 style={{ letterSpacing: 0.9 }}
74 >
75 {props.label}
76 </Text>
77 <Text selectable className="text-foreground text-[13px] font-medium" numberOfLines={1}>
78 {props.value}
79 </Text>
80 </View>
81 );
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 const iconColor = useThemeColor("--color-icon");
92 const iconSubtleColor = useThemeColor("--color-icon-subtle");
93​
94 return (
95 <Pressable
96 className="flex-row items-center gap-3 px-1 py-3"
97 disabled={props.disabled}
98 style={{ opacity: props.disabled ? 0.45 : 1 }}
99 onPress={props.onPress}
100 >
101 <View className="bg-subtle h-9 w-9 items-center justify-center rounded-full">
102 <SymbolView name={props.icon} size={16} tintColor={iconColor} type="monochrome" />
103 </View>
104 <View className="flex-1 gap-0.5">
105 <Text className="text-foreground text-[16px] font-t3-bold">{props.title}</Text>
106 {props.subtitle ? (
107 <Text className="text-foreground-muted text-[12px] leading-[17px]">{props.subtitle}</Text>
108 ) : null}
109 </View>
110 <SymbolView name="chevron.right" size={13} tintColor={iconSubtleColor} type="monochrome" />
111 </Pressable>
112 );
114​
115/* ─── Shared utilities ──────────────────────────────────────────────── */
116​
117export function menuItemIconName(
118 icon: "commit" | "push" | "pr",
119): ComponentProps<typeof SymbolView>["name"] {
120 if (icon === "commit") return "checkmark.circle";
121 if (icon === "push") return "arrow.up.circle";
122 return "arrow.up.right.circle";
124​
125export function statusSummary(
126 gitStatus: {
127 readonly isRepo?: boolean;
128 readonly hasWorkingTreeChanges?: boolean;
129 readonly workingTree?: { readonly files: readonly { readonly path: string }[] };
130 readonly aheadCount?: number;
131 readonly behindCount?: number;
132 readonly pr?: { readonly state?: string; readonly number?: number } | null;
133 } | null,
134): string {
135 if (!gitStatus) {
136 return "Loading branch status\u2026";
137 }
138​
139 if (!gitStatus.isRepo) {
140 return "Not a git repository";
141 }
142​
143 const parts: string[] = [];
144 if (gitStatus.hasWorkingTreeChanges) {
145 const fileCount = gitStatus.workingTree?.files.length ?? 0;
146 parts.push(`${fileCount} file${fileCount === 1 ? "" : "s"} changed`);
147 } else {
148 parts.push("Clean");
149 }
150 if ((gitStatus.aheadCount ?? 0) > 0) {
151 parts.push(`${gitStatus.aheadCount} ahead`);
152 }
153 if ((gitStatus.behindCount ?? 0) > 0) {
154 parts.push(`${gitStatus.behindCount} behind`);
155 }
156 if (gitStatus.pr?.state === "open") {
157 parts.push(`PR #${gitStatus.pr.number} open`);
158 }
159​
160 return parts.join(" \u00b7 ");