import { resolveDefaultBranchActionDialogCopy } from "@t3tools/client-runtime"; import { resolveAutoFeatureBranchName } from "@t3tools/shared/git"; import * as Arr from "effect/Array"; import * as Result from "effect/Result"; import { useLocalSearchParams, useRouter } from "expo-router"; import { useCallback, useMemo } from "react"; import { View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; 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"; export function GitConfirmSheet() { const router = useRouter(); const insets = useSafeAreaInsets(); const gitState = useSelectedThreadGitState(); const gitActions = useSelectedThreadGitActions(); const params = useLocalSearchParams<{ confirmAction?: string; branchName?: string; includesCommit?: string; commitMessage?: string; filePaths?: string; }>(); const confirmAction = params.confirmAction as | "push" | "create_pr" | "commit_push" | "commit_push_pr" | undefined; const branchName = params.branchName ?? ""; const includesCommit = params.includesCommit === "true"; const copy = useMemo( () => confirmAction ? resolveDefaultBranchActionDialogCopy({ action: confirmAction, branchName, includesCommit, }) : null, [branchName, confirmAction, includesCommit], ); const continuePendingAction = useCallback(async () => { if (!confirmAction) return; router.dismissAll(); await gitActions.onRunSelectedThreadGitAction({ action: confirmAction, ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), ...(params.filePaths ? { filePaths: params.filePaths.split(",") } : {}), }); }, [confirmAction, gitActions, params, router]); const movePendingActionToFeatureBranch = useCallback(async () => { if (!confirmAction) return; router.dismissAll(); 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, router]); return ( Confirm {copy?.title ?? "Run action on default branch?"} {copy?.description ?? "Choose how to continue."} void continuePendingAction()} /> void movePendingActionToFeatureBranch()} /> ); }