11import React , { useState , useCallback } from "react" ;
22import { Modal , ModalActions , CancelButton , PrimaryButton } from "./Modal" ;
3- import type { IPCApi } from "@/common/types/ipc" ;
4- import { DirectoryPickerModal } from "./DirectoryPickerModal" ;
53import type { ProjectConfig } from "@/node/config" ;
64
75interface ProjectCreateModalProps {
@@ -23,37 +21,14 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({
2321} ) => {
2422 const [ path , setPath ] = useState ( "" ) ;
2523 const [ error , setError ] = useState ( "" ) ;
26- // Detect desktop environment where native directory picker is available
27- const isDesktop =
28- window . api . platform !== "browser" && typeof window . api . projects . pickDirectory === "function" ;
29- const api = window . api as unknown as IPCApi ;
30- const hasWebFsPicker = window . api . platform === "browser" && ! ! api . fs ?. listDirectory ;
3124 const [ isCreating , setIsCreating ] = useState ( false ) ;
32- const [ isDirPickerOpen , setIsDirPickerOpen ] = useState ( false ) ;
3325
3426 const handleCancel = useCallback ( ( ) => {
3527 setPath ( "" ) ;
3628 setError ( "" ) ;
3729 onClose ( ) ;
3830 } , [ onClose ] ) ;
3931
40- const handleWebPickerPathSelected = useCallback ( ( selected : string ) => {
41- setPath ( selected ) ;
42- setError ( "" ) ;
43- } , [ ] ) ;
44-
45- const handleBrowse = useCallback ( async ( ) => {
46- try {
47- const selectedPath = await window . api . projects . pickDirectory ( ) ;
48- if ( selectedPath ) {
49- setPath ( selectedPath ) ;
50- setError ( "" ) ;
51- }
52- } catch ( err ) {
53- console . error ( "Failed to pick directory:" , err ) ;
54- }
55- } , [ ] ) ;
56-
5732 const handleSelect = useCallback ( async ( ) => {
5833 const trimmedPath = path . trim ( ) ;
5934 if ( ! trimmedPath ) {
@@ -103,14 +78,6 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({
10378 }
10479 } , [ path , onSuccess , onClose ] ) ;
10580
106- const handleBrowseClick = useCallback ( ( ) => {
107- if ( isDesktop ) {
108- void handleBrowse ( ) ;
109- } else if ( hasWebFsPicker ) {
110- setIsDirPickerOpen ( true ) ;
111- }
112- } , [ handleBrowse , hasWebFsPicker , isDesktop ] ) ;
113-
11481 const handleKeyDown = useCallback (
11582 ( e : React . KeyboardEvent ) => {
11683 if ( e . key === "Enter" ) {
@@ -122,55 +89,35 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({
12289 ) ;
12390
12491 return (
125- < >
126- < Modal
127- isOpen = { isOpen }
128- title = "Add Project"
129- subtitle = "Enter the path to your project directory"
130- onClose = { handleCancel }
131- isLoading = { isCreating }
132- >
133- < div className = "mb-5 flex gap-2" >
134- < input
135- type = "text"
136- value = { path }
137- onChange = { ( e ) => {
138- setPath ( e . target . value ) ;
139- setError ( "" ) ;
140- } }
141- onKeyDown = { handleKeyDown }
142- placeholder = "/home/user/projects/my-project"
143- autoFocus
144- disabled = { isCreating }
145- className = "bg-modal-bg border-border-medium focus:border-accent placeholder:text-muted w-full flex-1 rounded border px-3 py-2 font-mono text-sm text-foreground focus:outline-none disabled:opacity-50"
146- />
147- { ( isDesktop || hasWebFsPicker ) && (
148- < button
149- type = "button"
150- onClick = { handleBrowseClick }
151- disabled = { isCreating }
152- className = "bg-border-medium hover:bg-border-darker border-border-medium rounded border px-4 text-sm font-medium text-foreground transition-colors disabled:opacity-50"
153- >
154- Browse...
155- </ button >
156- ) }
157- </ div >
158- { error && < div className = "text-error -mt-3 mb-3 text-xs" > { error } </ div > }
159- < ModalActions >
160- < CancelButton onClick = { handleCancel } disabled = { isCreating } >
161- Cancel
162- </ CancelButton >
163- < PrimaryButton onClick = { ( ) => void handleSelect ( ) } disabled = { isCreating } >
164- { isCreating ? "Adding..." : "Add Project" }
165- </ PrimaryButton >
166- </ ModalActions >
167- </ Modal >
168- < DirectoryPickerModal
169- isOpen = { isDirPickerOpen }
170- initialPath = { path || "." }
171- onClose = { ( ) => setIsDirPickerOpen ( false ) }
172- onSelectPath = { handleWebPickerPathSelected }
92+ < Modal
93+ isOpen = { isOpen }
94+ title = "Add Project"
95+ subtitle = "Enter the path to your project directory"
96+ onClose = { handleCancel }
97+ isLoading = { isCreating }
98+ >
99+ < input
100+ type = "text"
101+ value = { path }
102+ onChange = { ( e ) => {
103+ setPath ( e . target . value ) ;
104+ setError ( "" ) ;
105+ } }
106+ onKeyDown = { handleKeyDown }
107+ placeholder = "/home/user/projects/my-project"
108+ autoFocus
109+ disabled = { isCreating }
110+ className = "bg-modal-bg border-border-medium focus:border-accent placeholder:text-muted text-foreground mb-5 w-full rounded border px-3 py-2 font-mono text-sm focus:outline-none disabled:opacity-50"
173111 />
174- </ >
112+ { error && < div className = "text-error -mt-3 mb-3 text-xs" > { error } </ div > }
113+ < ModalActions >
114+ < CancelButton onClick = { handleCancel } disabled = { isCreating } >
115+ Cancel
116+ </ CancelButton >
117+ < PrimaryButton onClick = { ( ) => void handleSelect ( ) } disabled = { isCreating } >
118+ { isCreating ? "Adding..." : "Add Project" }
119+ </ PrimaryButton >
120+ </ ModalActions >
121+ </ Modal >
175122 ) ;
176123} ;
0 commit comments