@@ -3,7 +3,14 @@ import { FolderPicker } from "@features/folder-picker/components/FolderPicker";
33import { GitHubRepoPicker } from "@features/folder-picker/components/GitHubRepoPicker" ;
44import { useFolders } from "@features/folders/hooks/useFolders" ;
55import { BranchSelector } from "@features/git-interaction/components/BranchSelector" ;
6+ import { GitBranchDialog } from "@features/git-interaction/components/GitInteractionDialogs" ;
67import { useGitQueries } from "@features/git-interaction/hooks/useGitQueries" ;
8+ import { useGitInteractionStore } from "@features/git-interaction/state/gitInteractionStore" ;
9+ import {
10+ sanitizeBranchName ,
11+ validateBranchName ,
12+ } from "@features/git-interaction/utils/branchNameValidation" ;
13+ import { invalidateGitBranchQueries } from "@features/git-interaction/utils/gitCacheKeys" ;
714import type { MessageEditorHandle } from "@features/message-editor/components/MessageEditor" ;
815import { ModeIndicatorInput } from "@features/message-editor/components/ModeIndicatorInput" ;
916import { DropZoneOverlay } from "@features/sessions/components/DropZoneOverlay" ;
@@ -22,7 +29,7 @@ import {
2229import { Flex } from "@radix-ui/themes" ;
2330import { useTRPC } from "@renderer/trpc/client" ;
2431import { useNavigationStore } from "@stores/navigationStore" ;
25- import { useQuery } from "@tanstack/react-query" ;
32+ import { useMutation , useQuery } from "@tanstack/react-query" ;
2633import { useCallback , useEffect , useRef , useState } from "react" ;
2734import { useHotkeys } from "react-hotkeys-hook" ;
2835import { usePreviewSession } from "../hooks/usePreviewSession" ;
@@ -94,6 +101,51 @@ export function TaskInput() {
94101 const cloudBranches = cloudBranchData ?. branches ;
95102 const cloudDefaultBranch = cloudBranchData ?. defaultBranch ?? null ;
96103
104+ const {
105+ branchOpen,
106+ branchName : newBranchName ,
107+ branchError,
108+ actions : gitActions ,
109+ } = useGitInteractionStore ( ) ;
110+
111+ const createBranchMutation = useMutation (
112+ trpcReact . git . createBranch . mutationOptions ( {
113+ onSuccess : ( _data , { branchName } ) => {
114+ if ( selectedDirectory ) invalidateGitBranchQueries ( selectedDirectory ) ;
115+ setSelectedBranch ( branchName ) ;
116+ gitActions . closeBranch ( ) ;
117+ } ,
118+ onError : ( error ) => {
119+ const message =
120+ error instanceof Error ? error . message : "Failed to create branch." ;
121+ gitActions . setBranchError ( message ) ;
122+ } ,
123+ } ) ,
124+ ) ;
125+
126+ const handleNewBranchNameChange = useCallback (
127+ ( value : string ) => {
128+ const sanitized = sanitizeBranchName ( value ) ;
129+ gitActions . setBranchName ( sanitized ) ;
130+ gitActions . setBranchError ( validateBranchName ( sanitized ) ) ;
131+ } ,
132+ [ gitActions ] ,
133+ ) ;
134+
135+ const handleCreateBranch = useCallback ( ( ) => {
136+ const trimmed = newBranchName . trim ( ) ;
137+ if ( ! trimmed || ! selectedDirectory ) return ;
138+ const validationError = validateBranchName ( trimmed ) ;
139+ if ( validationError ) {
140+ gitActions . setBranchError ( validationError ) ;
141+ return ;
142+ }
143+ createBranchMutation . mutate ( {
144+ directoryPath : selectedDirectory ,
145+ branchName : trimmed ,
146+ } ) ;
147+ } , [ newBranchName , selectedDirectory , gitActions , createBranchMutation ] ) ;
148+
97149 // Preview session provides adapter-specific config options
98150 const {
99151 modeOption,
@@ -398,6 +450,18 @@ export function TaskInput() {
398450 />
399451 </ Flex >
400452 </ Flex >
453+
454+ < GitBranchDialog
455+ open = { branchOpen }
456+ onOpenChange = { ( open ) => {
457+ if ( ! open ) gitActions . closeBranch ( ) ;
458+ } }
459+ branchName = { newBranchName }
460+ onBranchNameChange = { handleNewBranchNameChange }
461+ onConfirm = { handleCreateBranch }
462+ isSubmitting = { createBranchMutation . isPending }
463+ error = { branchError }
464+ />
401465 </ div >
402466 ) ;
403467}
0 commit comments