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