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

gitSheetComponents.tsx

69 lines2.1 KB

1import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2import { SymbolView } from "../../../components/ui/AppSymbol";
3import type { ComponentProps } from "react";
4import { View } from "react-native";
5import { Button } from "../../../components/ui/Button";
6​
7export function SheetActionButton(props: {
8 readonly icon: ComponentProps<typeof SymbolView>["name"];
9 readonly label: string;
10 readonly disabled?: boolean;
11 readonly tone?: "primary" | "secondary" | "danger";
12 readonly onPress: () => void;
13}) {
14 return (
15 <View className="flex-1">
16 <Button {...props} fullWidth />
17 </View>
18 );
20​
21export function menuItemIconName(
22 icon: "commit" | "push" | "pr",
23): ComponentProps<typeof SymbolView>["name"] {
24 if (icon === "commit") return "checkmark.circle";
25 if (icon === "push") return "arrow.up.circle";
26 return "arrow.up.right.circle";
28​
29export function statusSummary(
30 gitStatus: {
31 readonly isRepo?: boolean;
32 readonly hasWorkingTreeChanges?: boolean;
33 readonly workingTree?: { readonly files: readonly { readonly path: string }[] };
34 readonly aheadCount?: number;
35 readonly behindCount?: number;
36 readonly pr?: { readonly state?: string; readonly number?: number } | null;
37 readonly sourceControlProvider?: { readonly kind: string } | null;
38 } | null,
39): string {
40 if (!gitStatus) {
41 return "Loading branch status\u2026";
42 }
43​
44 if (!gitStatus.isRepo) {
45 return "Not a git repository";
46 }
47​
48 const parts: string[] = [];
49 if (gitStatus.hasWorkingTreeChanges) {
50 const fileCount = gitStatus.workingTree?.files.length ?? 0;
51 parts.push(`${fileCount} file${fileCount === 1 ? "" : "s"} changed`);
52 } else {
53 parts.push("Clean");
54 }
55 if ((gitStatus.aheadCount ?? 0) > 0) {
56 parts.push(`${gitStatus.aheadCount} ahead`);
57 }
58 if ((gitStatus.behindCount ?? 0) > 0) {
59 parts.push(`${gitStatus.behindCount} behind`);
60 }
61 if (gitStatus.pr?.state === "open") {
62 const { shortLabel } = sourceControlClients.get(
63 gitStatus.sourceControlProvider?.kind,
64 ).changeRequest;
65 parts.push(`${shortLabel} #${gitStatus.pr.number} open`);
66 }
67​
68 return parts.join(" \u00b7 ");