The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { resolveDefaultBranchActionDialogCopy } from "@t3tools/client-runtime/state/vcs"; |
| 2 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; |
| 3 | import { resolveAutoFeatureBranchName } from "@t3tools/shared/git"; |
| 4 | import * as Arr from "effect/Array"; |
| 5 | import * as Result from "effect/Result"; |
| 6 | import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native"; |
| 7 | import { useGT, useMessages } from "gt-react-native"; |
| 8 | import { useCallback, useMemo } from "react"; |
| 9 | import { View } from "react-native"; |
| 10 | |
| 11 | import { SheetHeader } from "../../../components/ui/SheetHeader"; |
| 12 | import { FitSheet } from "../../../components/ui/FitSheet"; |
| 13 | import { SheetIntro } from "../../../components/ui/SheetIntro"; |
| 14 | import { useSelectedThreadGitActions } from "../../../state/use-selected-thread-git-actions"; |
| 15 | import { useSelectedThreadGitState } from "../../../state/use-selected-thread-git-state"; |
| 16 | import { useThreadSelection } from "../../../state/use-thread-selection"; |
| 17 | import { SheetActionButton } from "./gitSheetComponents"; |
| 18 | |
| 19 | type GitConfirmSheetProps = StaticScreenProps<{ |
| 20 | readonly environmentId: string; |
| 21 | readonly threadId: string; |
| 22 | readonly confirmAction?: string; |
| 23 | readonly branchName?: string; |
| 24 | readonly includesCommit?: string; |
| 25 | readonly commitMessage?: string; |
| 26 | readonly filePaths?: string; |
| 27 | }>; |
| 28 | |
| 29 | export function GitConfirmSheet(props: GitConfirmSheetProps) { |
| 30 | const gt = useGT(); |
| 31 | const messages = useMessages(); |
| 32 | const navigation = useNavigation(); |
| 33 | const gitState = useSelectedThreadGitState(); |
| 34 | const gitActions = useSelectedThreadGitActions(); |
| 35 | const { canWriteSourceControl, canChangeThreadBranch } = gitActions; |
| 36 | const { selectedThreadProject } = useThreadSelection(); |
| 37 | const terminology = sourceControlClients.get( |
| 38 | selectedThreadProject?.repositoryIdentity?.provider, |
| 39 | ).changeRequest; |
| 40 | |
| 41 | const params = props.route.params; |
| 42 | |
| 43 | const confirmAction = params.confirmAction as |
| 44 | | "push" |
| 45 | | "create_pr" |
| 46 | | "commit_push" |
| 47 | | "commit_push_pr" |
| 48 | | undefined; |
| 49 | const branchName = params.branchName ?? ""; |
| 50 | const includesCommit = params.includesCommit === "true"; |
| 51 | const environmentId = params.environmentId ?? ""; |
| 52 | const threadId = params.threadId ?? ""; |
| 53 | |
| 54 | const copy = useMemo( |
| 55 | () => |
| 56 | confirmAction |
| 57 | ? resolveDefaultBranchActionDialogCopy( |
| 58 | { |
| 59 | action: confirmAction, |
| 60 | branchName, |
| 61 | includesCommit, |
| 62 | terminology, |
| 63 | }, |
| 64 | messages, |
| 65 | ) |
| 66 | : null, |
| 67 | [branchName, confirmAction, includesCommit, messages, terminology], |
| 68 | ); |
| 69 | |
| 70 | const continuePendingAction = async () => { |
| 71 | if (!canWriteSourceControl || !confirmAction) return; |
| 72 | navigation.dispatch(StackActions.replace("Thread", { environmentId, threadId })); |
| 73 | await gitActions.onRunSelectedThreadGitAction({ |
| 74 | action: confirmAction, |
| 75 | ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), |
| 76 | ...(params.filePaths ? { filePaths: params.filePaths.split(",") } : {}), |
| 77 | }); |
| 78 | }; |
| 79 | |
| 80 | const movePendingActionToFeatureBranch = useCallback(async () => { |
| 81 | if (!canChangeThreadBranch || !confirmAction) return; |
| 82 | navigation.dispatch(StackActions.replace("Thread", { environmentId, threadId })); |
| 83 | |
| 84 | if (includesCommit) { |
| 85 | await gitActions.onRunSelectedThreadGitAction({ |
| 86 | action: confirmAction, |
| 87 | featureBranch: true, |
| 88 | ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), |
| 89 | ...(params.filePaths ? { filePaths: params.filePaths.split(",") } : {}), |
| 90 | }); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | const branches = |
| 95 | gitState.selectedThreadBranches.length > 0 |
| 96 | ? gitState.selectedThreadBranches |
| 97 | : await gitActions.refreshSelectedThreadBranches(); |
| 98 | if (branches === null) return; |
| 99 | const newBranchName = resolveAutoFeatureBranchName( |
| 100 | Arr.filterMap(branches, (branch) => |
| 101 | branch.isRemote ? Result.failVoid : Result.succeed(branch.name), |
| 102 | ), |
| 103 | ); |
| 104 | const created = await gitActions.onCreateSelectedThreadBranch(newBranchName); |
| 105 | if (created === null) return; |
| 106 | await gitActions.onRunSelectedThreadGitAction({ action: confirmAction }); |
| 107 | }, [ |
| 108 | canChangeThreadBranch, |
| 109 | confirmAction, |
| 110 | gitActions, |
| 111 | gitState.selectedThreadBranches, |
| 112 | includesCommit, |
| 113 | params, |
| 114 | navigation, |
| 115 | environmentId, |
| 116 | threadId, |
| 117 | ]); |
| 118 | |
| 119 | return ( |
| 120 | <FitSheet |
| 121 | header={<SheetHeader title={gt("Confirm action")} onClose={() => navigation.goBack()} />} |
| 122 | showsVerticalScrollIndicator={false} |
| 123 | > |
| 124 | <SheetIntro |
| 125 | eyebrow={gt("Confirm", { $context: "eyebrow label above a confirmation title" })} |
| 126 | title={copy?.title ?? gt("Run action on default branch?")} |
| 127 | description={copy?.description ?? gt("Choose how to continue.")} |
| 128 | /> |
| 129 | |
| 130 | <View className="gap-3"> |
| 131 | <SheetActionButton |
| 132 | icon="arrow.right.circle" |
| 133 | label={copy?.continueLabel ?? gt("Continue")} |
| 134 | disabled={!canWriteSourceControl} |
| 135 | onPress={() => void continuePendingAction()} |
| 136 | /> |
| 137 | <SheetActionButton |
| 138 | icon="arrow.branch" |
| 139 | label={gt("Feature branch & continue")} |
| 140 | disabled={!canChangeThreadBranch} |
| 141 | tone="primary" |
| 142 | onPress={() => void movePendingActionToFeatureBranch()} |
| 143 | /> |
| 144 | </View> |
| 145 | </FitSheet> |
| 146 | ); |
| 147 | } |