The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; |
| 2 | import { changeRequestTermKind } from "../../../lib/changeRequestTerm"; |
| 3 | import { SymbolView } from "../../../components/ui/AppSymbol"; |
| 4 | import { msg } from "gt-react-native"; |
| 5 | import type { ComponentProps } from "react"; |
| 6 | import { View } from "react-native"; |
| 7 | import { Button } from "../../../components/ui/Button"; |
| 8 | import type { MessageResolver } from "../../../i18n/messages"; |
| 9 | |
| 10 | export 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 | return ( |
| 18 | <View className="flex-1"> |
| 19 | <Button {...props} fullWidth /> |
| 20 | </View> |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | export function menuItemIconName( |
| 25 | icon: "commit" | "push" | "pr", |
| 26 | ): ComponentProps<typeof SymbolView>["name"] { |
| 27 | if (icon === "commit") return "checkmark.circle"; |
| 28 | if (icon === "push") return "arrow.up.circle"; |
| 29 | return "arrow.up.right.circle"; |
| 30 | } |
| 31 | |
| 32 | export function statusSummary( |
| 33 | gitStatus: { |
| 34 | readonly isRepo?: boolean; |
| 35 | readonly hasWorkingTreeChanges?: boolean; |
| 36 | readonly workingTree?: { readonly files: readonly { readonly path: string }[] }; |
| 37 | readonly aheadCount?: number; |
| 38 | readonly behindCount?: number; |
| 39 | readonly pr?: { readonly state?: string; readonly number?: number } | null; |
| 40 | readonly sourceControlProvider?: { readonly kind: string } | null; |
| 41 | } | null, |
| 42 | resolve: MessageResolver, |
| 43 | ): string { |
| 44 | if (!gitStatus) { |
| 45 | return resolve(msg("Loading branch status\u2026")); |
| 46 | } |
| 47 | |
| 48 | if (!gitStatus.isRepo) { |
| 49 | return resolve(msg("Not a git repository")); |
| 50 | } |
| 51 | |
| 52 | const parts: string[] = []; |
| 53 | if (gitStatus.hasWorkingTreeChanges) { |
| 54 | const fileCount = gitStatus.workingTree?.files.length ?? 0; |
| 55 | parts.push( |
| 56 | resolve( |
| 57 | msg("{count, plural, one {{count} file changed} other {{count} files changed}}", { |
| 58 | count: fileCount, |
| 59 | }), |
| 60 | ), |
| 61 | ); |
| 62 | } else { |
| 63 | parts.push(resolve(msg("Clean", { $context: "git working tree has no changes" }))); |
| 64 | } |
| 65 | if ((gitStatus.aheadCount ?? 0) > 0) { |
| 66 | parts.push( |
| 67 | resolve( |
| 68 | msg("{count, plural, one {{count} ahead} other {{count} ahead}}", { |
| 69 | count: gitStatus.aheadCount, |
| 70 | }), |
| 71 | ), |
| 72 | ); |
| 73 | } |
| 74 | if ((gitStatus.behindCount ?? 0) > 0) { |
| 75 | parts.push( |
| 76 | resolve( |
| 77 | msg("{count, plural, one {{count} behind} other {{count} behind}}", { |
| 78 | count: gitStatus.behindCount, |
| 79 | }), |
| 80 | ), |
| 81 | ); |
| 82 | } |
| 83 | if (gitStatus.pr?.state === "open") { |
| 84 | const term = changeRequestTermKind( |
| 85 | sourceControlClients.get(gitStatus.sourceControlProvider?.kind).changeRequest, |
| 86 | ); |
| 87 | parts.push( |
| 88 | resolve( |
| 89 | msg( |
| 90 | "{term, select, mr {MR #{number} open} cr {change request #{number} open} other {PR #{number} open}}", |
| 91 | { term, number: gitStatus.pr.number }, |
| 92 | ), |
| 93 | ), |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | return parts.join(" \u00b7 "); |
| 98 | } |