@@ -46,18 +46,16 @@ function AppInner() {
4646 selectedWorkspace,
4747 setSelectedWorkspace,
4848 } = useApp ( ) ;
49- const [ workspaceModalOpen , setWorkspaceModalOpen ] = useState ( false ) ;
50- const [ workspaceModalProject , setWorkspaceModalProject ] = useState < string | null > ( null ) ;
51- const [ workspaceModalProjectName , setWorkspaceModalProjectName ] = useState < string > ( "" ) ;
52- const [ workspaceModalBranches , setWorkspaceModalBranches ] = useState < string [ ] > ( [ ] ) ;
53- const [ workspaceModalDefaultTrunk , setWorkspaceModalDefaultTrunk ] = useState < string | undefined > (
54- undefined
55- ) ;
56- const [ workspaceModalLoadError , setWorkspaceModalLoadError ] = useState < string | null > ( null ) ;
57- const [ workspaceModalStartMessage , setWorkspaceModalStartMessage ] = useState < string | undefined > (
58- undefined
59- ) ;
60- const [ workspaceModalModel , setWorkspaceModalModel ] = useState < string | undefined > ( undefined ) ;
49+ const [ workspaceModalState , setWorkspaceModalState ] = useState ( {
50+ isOpen : false ,
51+ projectPath : null as string | null ,
52+ projectName : "" ,
53+ branches : [ ] as string [ ] ,
54+ defaultTrunk : undefined as string | undefined ,
55+ loadError : null as string | null ,
56+ startMessage : undefined as string | undefined ,
57+ model : undefined as string | undefined ,
58+ } ) ;
6159 const workspaceModalProjectRef = useRef < string | null > ( null ) ;
6260
6361 // Auto-collapse sidebar on mobile by default
@@ -188,14 +186,16 @@ function AppInner() {
188186 projectPath . split ( "/" ) . pop ( ) ?? projectPath . split ( "\\" ) . pop ( ) ?? "project" ;
189187
190188 workspaceModalProjectRef . current = projectPath ;
191- setWorkspaceModalProject ( projectPath ) ;
192- setWorkspaceModalProjectName ( projectName ) ;
193- setWorkspaceModalBranches ( [ ] ) ;
194- setWorkspaceModalDefaultTrunk ( undefined ) ;
195- setWorkspaceModalLoadError ( initialData ?. error ?? null ) ;
196- setWorkspaceModalStartMessage ( initialData ?. startMessage ) ;
197- setWorkspaceModalModel ( initialData ?. model ) ;
198- setWorkspaceModalOpen ( true ) ;
189+ setWorkspaceModalState ( {
190+ isOpen : true ,
191+ projectPath,
192+ projectName,
193+ branches : [ ] ,
194+ defaultTrunk : undefined ,
195+ loadError : initialData ?. error ?? null ,
196+ startMessage : initialData ?. startMessage ,
197+ model : initialData ?. model ,
198+ } ) ;
199199
200200 try {
201201 const branchResult = await window . api . projects . listBranches ( projectPath ) ;
@@ -215,15 +215,19 @@ function AppInner() {
215215 ? branchResult . recommendedTrunk
216216 : sanitizedBranches [ 0 ] ;
217217
218- setWorkspaceModalBranches ( sanitizedBranches ) ;
219- setWorkspaceModalDefaultTrunk ( recommended ) ;
220- setWorkspaceModalLoadError ( null ) ;
218+ setWorkspaceModalState ( ( prev ) => ( {
219+ ...prev ,
220+ branches : sanitizedBranches ,
221+ defaultTrunk : recommended ,
222+ loadError : null ,
223+ } ) ) ;
221224 } catch ( err ) {
222225 console . error ( "Failed to load branches for modal:" , err ) ;
223226 const message = err instanceof Error ? err . message : "Unknown error" ;
224- setWorkspaceModalLoadError (
225- `Unable to load branches automatically: ${ message } . You can still enter the trunk branch manually.`
226- ) ;
227+ setWorkspaceModalState ( ( prev ) => ( {
228+ ...prev ,
229+ loadError : `Unable to load branches automatically: ${ message } . You can still enter the trunk branch manually.` ,
230+ } ) ) ;
227231 }
228232 } ,
229233 [ ]
@@ -255,7 +259,7 @@ function AppInner() {
255259 startMessage ?: string ,
256260 model ?: string
257261 ) => {
258- if ( ! workspaceModalProject ) return ;
262+ if ( ! workspaceModalState . projectPath ) return ;
259263
260264 console . assert (
261265 typeof trunkBranch === "string" && trunkBranch . trim ( ) . length > 0 ,
@@ -274,7 +278,7 @@ function AppInner() {
274278 }
275279
276280 const newWorkspace = await createWorkspace (
277- workspaceModalProject ,
281+ workspaceModalState . projectPath ,
278282 branchName ,
279283 trunkBranch ,
280284 runtimeConfig
@@ -286,7 +290,7 @@ function AppInner() {
286290
287291 // Save runtime preference for this project if provided
288292 if ( runtime ) {
289- const runtimeKey = getRuntimeKey ( workspaceModalProject ) ;
293+ const runtimeKey = getRuntimeKey ( workspaceModalState . projectPath ) ;
290294 localStorage . setItem ( runtimeKey , runtime ) ;
291295 }
292296
@@ -733,26 +737,28 @@ function AppInner() {
733737 workspaceId : selectedWorkspace ?. workspaceId ,
734738 } ) }
735739 />
736- { workspaceModalOpen && workspaceModalProject && (
740+ { workspaceModalState . isOpen && workspaceModalState . projectPath && (
737741 < NewWorkspaceModal
738- isOpen = { workspaceModalOpen }
739- projectName = { workspaceModalProjectName }
740- projectPath = { workspaceModalProject }
741- branches = { workspaceModalBranches }
742- defaultTrunkBranch = { workspaceModalDefaultTrunk }
743- loadErrorMessage = { workspaceModalLoadError }
744- initialStartMessage = { workspaceModalStartMessage }
745- initialModel = { workspaceModalModel }
742+ isOpen = { workspaceModalState . isOpen }
743+ projectName = { workspaceModalState . projectName }
744+ projectPath = { workspaceModalState . projectPath }
745+ branches = { workspaceModalState . branches }
746+ defaultTrunkBranch = { workspaceModalState . defaultTrunk }
747+ loadErrorMessage = { workspaceModalState . loadError }
748+ initialStartMessage = { workspaceModalState . startMessage }
749+ initialModel = { workspaceModalState . model }
746750 onClose = { ( ) => {
747751 workspaceModalProjectRef . current = null ;
748- setWorkspaceModalOpen ( false ) ;
749- setWorkspaceModalProject ( null ) ;
750- setWorkspaceModalProjectName ( "" ) ;
751- setWorkspaceModalBranches ( [ ] ) ;
752- setWorkspaceModalDefaultTrunk ( undefined ) ;
753- setWorkspaceModalLoadError ( null ) ;
754- setWorkspaceModalStartMessage ( undefined ) ;
755- setWorkspaceModalModel ( undefined ) ;
752+ setWorkspaceModalState ( {
753+ isOpen : false ,
754+ projectPath : null ,
755+ projectName : "" ,
756+ branches : [ ] ,
757+ defaultTrunk : undefined ,
758+ loadError : null ,
759+ startMessage : undefined ,
760+ model : undefined ,
761+ } ) ;
756762 } }
757763 onAdd = { handleCreateWorkspace }
758764 />
0 commit comments