@@ -14,14 +14,37 @@ interface NewDirectoryComponentProps {
1414}
1515
1616const NewDirectoryComponent : React . FC < NewDirectoryComponentProps > = ( { isOpen, onClose, parentDirectoryPath } ) => {
17- const [ directoryName , setDirectoryName ] = useState < string > ( '' )
17+ const [ directoryRelativePath , setDirectoryRelativePath ] = useState < string > ( '' )
1818 const [ errorMessage , setErrorMessage ] = useState < string | null > ( null )
1919
20- const { currentlyOpenFilePath } = useFileContext ( )
20+ const { selectedDirectory } = useFileContext ( )
21+
22+ useEffect ( ( ) => {
23+ const setupInitialPath = async ( ) => {
24+ const vaultDirectory = await window . electronStore . getVaultDirectoryForWindow ( )
25+
26+ let fullPath = ''
27+ if ( parentDirectoryPath ) {
28+ fullPath = parentDirectoryPath
29+ } else if ( selectedDirectory ) {
30+ fullPath = selectedDirectory
31+ }
32+
33+ if ( fullPath ) {
34+ const relativePath = await window . path . relative ( vaultDirectory , fullPath )
35+ const pathWithSeparator = relativePath ? `${ relativePath } ${ await window . path . pathSep ( ) } ` : ''
36+ setDirectoryRelativePath ( pathWithSeparator )
37+ }
38+ }
39+
40+ if ( isOpen ) {
41+ setupInitialPath ( )
42+ }
43+ } , [ isOpen , parentDirectoryPath , selectedDirectory ] )
2144
2245 useEffect ( ( ) => {
2346 if ( ! isOpen ) {
24- setDirectoryName ( '' )
47+ setDirectoryRelativePath ( '' )
2548 setErrorMessage ( null )
2649 }
2750 } , [ isOpen ] )
@@ -39,24 +62,25 @@ const NewDirectoryComponent: React.FC<NewDirectoryComponentProps> = ({ isOpen, o
3962 const handleNameChange = async ( e : React . ChangeEvent < HTMLInputElement > ) => {
4063 const newName = e . target . value
4164 await handleValidName ( newName )
42- setDirectoryName ( newName )
65+ setDirectoryRelativePath ( newName )
4366 }
4467
45- const sendNewDirectoryMsg = async ( ) => {
46- const validName = await handleValidName ( directoryName )
47- if ( ! directoryName || errorMessage || ! validName ) return
68+ const createNewDirectory = async ( ) => {
69+ const validName = await handleValidName ( directoryRelativePath )
70+ if ( ! directoryRelativePath || errorMessage || ! validName ) return
4871
49- let directoryPath : string
72+ // let directoryPath: string
73+ const directoryPath = await window . electronStore . getVaultDirectoryForWindow ( )
5074
51- if ( parentDirectoryPath ) {
52- directoryPath = parentDirectoryPath
53- } else if ( currentlyOpenFilePath && currentlyOpenFilePath !== '' ) {
54- directoryPath = await window . path . dirname ( currentlyOpenFilePath )
55- } else {
56- directoryPath = await window . electronStore . getVaultDirectoryForWindow ( )
57- }
75+ // if (parentDirectoryPath) {
76+ // directoryPath = parentDirectoryPath
77+ // } else if (currentlyOpenFilePath && currentlyOpenFilePath !== '') {
78+ // directoryPath = await window.path.dirname(currentlyOpenFilePath)
79+ // } else {
80+ // directoryPath = await window.electronStore.getVaultDirectoryForWindow()
81+ // }
5882
59- const finalPath = await window . path . join ( directoryPath , directoryName )
83+ const finalPath = await window . path . join ( directoryPath , directoryRelativePath )
6084 window . fileSystem . createDirectory ( finalPath )
6185 posthog . capture ( 'created_new_directory_from_new_directory_modal' )
6286 onClose ( )
@@ -69,11 +93,11 @@ const NewDirectoryComponent: React.FC<NewDirectoryComponentProps> = ({ isOpen, o
6993 < input
7094 type = "text"
7195 className = " block w-full rounded-md border border-gray-300 px-3 py-2 transition duration-150 ease-in-out focus:border-blue-300 focus:outline-none"
72- value = { directoryName }
96+ value = { directoryRelativePath }
7397 onChange = { handleNameChange }
7498 onKeyDown = { ( e : React . KeyboardEvent < HTMLInputElement > ) => {
7599 if ( e . key === 'Enter' ) {
76- sendNewDirectoryMsg ( )
100+ createNewDirectory ( )
77101 }
78102 } }
79103 placeholder = "Directory Name"
@@ -84,7 +108,7 @@ const NewDirectoryComponent: React.FC<NewDirectoryComponentProps> = ({ isOpen, o
84108 < div className = "flex items-center gap-3" >
85109 < Button
86110 className = "mb-2 mt-3 h-10 w-[80px] cursor-pointer border-none bg-blue-500 px-2 py-0 text-center hover:bg-blue-600"
87- onClick = { sendNewDirectoryMsg }
111+ onClick = { createNewDirectory }
88112 placeholder = ""
89113 >
90114 Create
0 commit comments