import { resolveDefaultBranchActionDialogCopy } from "@t3tools/client-runtime/state/vcs"; import { resolveAutoFeatureBranchName } from "@t3tools/shared/git"; import * as Arr from "effect/Array"; import * as Result from "effect/Result"; import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native"; import { useCallback, useMemo } from "react"; import { Platform, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { AndroidSheetHeader } from "../../../components/AndroidScreenHeader"; import { AppText as Text } from "../../../components/AppText"; import { useSelectedThreadGitActions } from "../../../state/use-selected-thread-git-actions"; import { useSelectedThreadGitState } from "../../../state/use-selected-thread-git-state"; import { SheetActionButton } from "./gitSheetComponents"; type GitConfirmSheetProps = StaticScreenProps<{ readonly environmentId: string; readonly threadId: string; readonly confirmAction?: string; readonly branchName?: string; readonly includesCommit?: string; readonly commitMessage?: string; readonly filePaths?: string; }>; export function GitConfirmSheet(props: GitConfirmSheetProps) { const navigation = useNavigation(); const insets = useSafeAreaInsets(); const gitState = useSelectedThreadGitState(); const gitActions = useSelectedThreadGitActions(); const params = props.route.params; const confirmAction = params.confirmAction as | "push" | "create_pr" | "commit_push" | "commit_push_pr" | undefined; const branchName = params.branchName ?? ""; const includesCommit = params.includesCommit === "true"; const environmentId = params.environmentId ?? ""; const threadId = params.threadId ?? ""; const copy = useMemo( () => confirmAction ? resolveDefaultBranchActionDialogCopy({ action: confirmAction, branchName, includesCommit, }) : null, [branchName, confirmAction, includesCommit], ); const continuePendingAction = useCallback(async () => { if (!confirmAction) return; navigation.dispatch(StackActions.replace("Thread", { environmentId, threadId })); await gitActions.onRunSelectedThreadGitAction({ action: confirmAction, ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), ...(params.filePaths ? { filePaths: params.filePaths.split(",") } : {}), }); }, [confirmAction, environmentId, gitActions, params, navigation, threadId]); const movePendingActionToFeatureBranch = useCallback(async () => { if (!confirmAction) return; navigation.dispatch(StackActions.replace("Thread", { environmentId, threadId })); if (includesCommit) { await gitActions.onRunSelectedThreadGitAction({ action: confirmAction, featureBranch: true, ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), ...(params.filePaths ? { filePaths: params.filePaths.split(",") } : {}), }); return; } const branches = gitState.selectedThreadBranches.length > 0 ? gitState.selectedThreadBranches : await gitActions.refreshSelectedThreadBranches(); const newBranchName = resolveAutoFeatureBranchName( Arr.filterMap(branches, (branch) => branch.isRemote ? Result.failVoid : Result.succeed(branch.name), ), ); await gitActions.onCreateSelectedThreadBranch(newBranchName); await gitActions.onRunSelectedThreadGitAction({ action: confirmAction }); }, [ confirmAction, gitActions, gitState.selectedThreadBranches, includesCommit, params, navigation, environmentId, threadId, ]); return ( {Platform.OS === "android" ? ( navigation.goBack()} /> ) : ( )} Confirm {copy?.title ?? "Run action on default branch?"} {copy?.description ?? "Choose how to continue."} void continuePendingAction()} /> void movePendingActionToFeatureBranch()} /> ); }