@@ -32,28 +32,35 @@ const Configuration = () => {
32
32
// Hooks for translation and context
33
33
const [ t ] = useTranslation ( "global" ) ;
34
34
const { configuration, setConfiguration } = useContext ( ConfigurationContext ) ;
35
- const [ error , setError ] = useState ( "" ) ;
35
+ const [ errorFolder , setErrorFolder ] = useState ( "" ) ;
36
+ const [ errorName , setErrorName ] = useState ( "" ) ;
36
37
37
- const checkFolderExists = ( folderPath : string ) => {
38
- if ( folderPath ) {
38
+ const checkExists = ( path : string , type : string ) => {
39
+ if ( path ) {
39
40
vscode . postMessage ( {
40
- command : "checkFolderExists " ,
41
+ command : "checkExists " ,
41
42
data : {
42
- folderPath,
43
+ path,
44
+ type,
43
45
} ,
44
46
} ) ;
45
47
} 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" ) ) ;
47
51
}
48
52
} ;
49
53
50
54
useEffect ( ( ) => {
51
55
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" ) : "" ) ;
57
64
}
58
65
}
59
66
} ;
@@ -84,12 +91,13 @@ const Configuration = () => {
84
91
} ) ;
85
92
} }
86
93
onBlur = { ( e : any ) => {
87
- checkFolderExists ( e . target . value ) ;
94
+ checkExists ( e . target . value , "folder" ) ;
88
95
} }
89
96
placeholder = { t ( "configuration.form.projectFolder.placeholder" ) }
90
- className = { error ? "error-textField" : "" }
97
+ className = { errorFolder ? "error-textField" : "" }
91
98
/>
92
- { error && < div className = "error-message" > { error } </ div > }
99
+ { errorFolder && < div className = "error-message" > { errorFolder } </ div > }
100
+ { errorName && < div className = "error-message" > { errorName } </ div > }
93
101
</ div >
94
102
< div className = "slash-separator" >
95
103
< p > /</ p >
@@ -107,7 +115,16 @@ const Configuration = () => {
107
115
projectName : e . target . value ,
108
116
} ) ;
109
117
} }
118
+ onBlur = { ( e : any ) => {
119
+ checkExists (
120
+ e . target . value
121
+ ? configuration . projectFolder + "/" + e . target . value
122
+ : e . target . value ,
123
+ "name" ,
124
+ ) ;
125
+ } }
110
126
placeholder = { t ( "configuration.form.projectName.placeholder" ) }
127
+ className = { errorName ? "error-textField" : "" }
111
128
/>
112
129
</ div >
113
130
</ div >
0 commit comments