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

gitSheetComponents.tsx

171 lines5.4 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​
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 );
71​
72export function MetaCard(props: { readonly label: string; readonly value: string }) {
73 return (
74 <View className="bg-card px-4 py-3 android:rounded-[20px] ios:rounded-[18px] ios:border ios:border-border">
75 <Text className="text-foreground-muted text-2xs font-t3-bold tracking-[0.9px] uppercase">
76 {props.label}
77 </Text>
78 <Text selectable className="text-foreground text-sm font-medium" numberOfLines={1}>
79 {props.value}
80 </Text>
81 </View>
82 );
84​
85export function SheetListRow(props: {
86 readonly icon: ComponentProps<typeof SymbolView>["name"];
87 readonly iconTintClassName?: string | undefined;
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={props.iconTintClassName ?? "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​
127export function menuItemIconName(
128 icon: "commit" | "push" | "pr",
129): ComponentProps<typeof SymbolView>["name"] {
130 if (icon === "commit") return "checkmark.circle";
131 if (icon === "push") return "arrow.up.circle";
132 return "arrow.up.right.circle";
134​
135export function statusSummary(
136 gitStatus: {
137 readonly isRepo?: boolean;
138 readonly hasWorkingTreeChanges?: boolean;
139 readonly workingTree?: { readonly files: readonly { readonly path: string }[] };
140 readonly aheadCount?: number;
141 readonly behindCount?: number;
142 readonly pr?: { readonly state?: string; readonly number?: number } | null;
143 } | null,
144): string {
145 if (!gitStatus) {
146 return "Loading branch status\u2026";
147 }
148​
149 if (!gitStatus.isRepo) {
150 return "Not a git repository";
151 }
152​
153 const parts: string[] = [];
154 if (gitStatus.hasWorkingTreeChanges) {
155 const fileCount = gitStatus.workingTree?.files.length ?? 0;
156 parts.push(`${fileCount} file${fileCount === 1 ? "" : "s"} changed`);
157 } else {
158 parts.push("Clean");
159 }
160 if ((gitStatus.aheadCount ?? 0) > 0) {
161 parts.push(`${gitStatus.aheadCount} ahead`);
162 }
163 if ((gitStatus.behindCount ?? 0) > 0) {
164 parts.push(`${gitStatus.behindCount} behind`);
165 }
166 if (gitStatus.pr?.state === "open") {
167 parts.push(`PR #${gitStatus.pr.number} open`);
168 }
169​
170 return parts.join(" \u00b7 ");