@@ -32,28 +32,35 @@ const Configuration = () => {
3232 // Hooks for translation and context
3333 const [ t ] = useTranslation ( "global" ) ;
3434 const { configuration, setConfiguration } = useContext ( ConfigurationContext ) ;
35- const [ error , setError ] = useState ( "" ) ;
35+ const [ errorFolder , setErrorFolder ] = useState ( "" ) ;
36+ const [ errorName , setErrorName ] = useState ( "" ) ;
3637
37- const checkFolderExists = ( folderPath : string ) => {
38- if ( folderPath ) {
38+ const checkExists = ( path : string , type : string ) => {
39+ if ( path ) {
3940 vscode . postMessage ( {
40- command : "checkFolderExists " ,
41+ command : "checkExists " ,
4142 data : {
42- folderPath,
43+ path,
44+ type,
4345 } ,
4446 } ) ;
4547 } else {
46- setError ( t ( "configuration.error.emptyPath" ) ) ;
48+ if ( type === "folder" ) setErrorFolder ( t ( "configuration.error.emptyPath" ) ) ;
49+ else if ( type === "name" )
50+ setErrorName ( t ( "configuration.error.emptyName" ) ) ;
4751 }
4852 } ;
4953
5054 useEffect ( ( ) => {
5155 const listener = ( event : any ) => {
52- if ( event . data . command === "folderCheckResult" ) {
53- if ( ! event . data . data . exists ) {
54- setError ( t ( "configuration.error.folderDoesNotExist" ) ) ;
55- } else {
56- setError ( "" ) ;
56+ if ( event . data . command === "checkResult" ) {
57+ const { exists, type } = event . data . data ;
58+ if ( type === "folder" ) {
59+ setErrorFolder (
60+ exists ? "" : t ( "configuration.error.folderDoesNotExist" ) ,
61+ ) ;
62+ } else if ( type === "name" ) {
63+ setErrorName ( exists ? t ( "configuration.error.alreadyExists" ) : "" ) ;
5764 }
5865 }
5966 } ;
@@ -84,12 +91,13 @@ const Configuration = () => {
8491 } ) ;
8592 } }
8693 onBlur = { ( e : any ) => {
87- checkFolderExists ( e . target . value ) ;
94+ checkExists ( e . target . value , "folder" ) ;
8895 } }
8996 placeholder = { t ( "configuration.form.projectFolder.placeholder" ) }
90- className = { error ? "error-textField" : "" }
97+ className = { errorFolder ? "error-textField" : "" }
9198 />
92- { error && < div className = "error-message" > { error } </ div > }
99+ { errorFolder && < div className = "error-message" > { errorFolder } </ div > }
100+ { errorName && < div className = "error-message" > { errorName } </ div > }
93101 </ div >
94102 < div className = "slash-separator" >
95103 < p > /</ p >
@@ -107,7 +115,16 @@ const Configuration = () => {
107115 projectName : e . target . value ,
108116 } ) ;
109117 } }
118+ onBlur = { ( e : any ) => {
119+ checkExists (
120+ e . target . value
121+ ? configuration . projectFolder + "/" + e . target . value
122+ : e . target . value ,
123+ "name" ,
124+ ) ;
125+ } }
110126 placeholder = { t ( "configuration.form.projectName.placeholder" ) }
127+ className = { errorName ? "error-textField" : "" }
111128 />
112129 </ div >
113130 </ div >
0 commit comments