@ -253,32 +253,34 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
}
}
// const createNewFolder = async (newFolderPath: string) => {
const createNewFolder = async ( newFolderPath : string ) = > {
// const fileManager = state.fileManager
const fileManager = state . fileManager
// const dirName = newFolderPath + '/'
const dirName = newFolderPath + '/'
// try {
try {
// const exists = await fileManager.exists(dirName)
const exists = await fileManager . exists ( dirName )
// if (exists) {
if ( exists ) {
// return modal('Rename File Failed', `A file or folder ${extractNameFromKey(newFolderPath)} already exists at this location. Please choose a different name.`, {
return modal ( 'Rename File Failed' , ` A file or folder ${ extractNameFromKey ( newFolderPath ) } already exists at this location. Please choose a different name. ` , {
// label: 'Close',
label : 'Close' ,
// fn: () => {}
fn : ( ) = > { }
// }, null)
} , null )
// }
}
// await fileManager.mkdir(dirName)
await fileManager . mkdir ( dirName )
// setState(prevState => {
setState ( prevState = > {
// return { ...prevState, focusElement: [{ key: newFolderPath, type: 'folder' }] }
return { . . . prevState , focusElement : [ { key : newFolderPath , type : 'folder' } ] }
// })
} )
// } catch (e) {
} catch ( e ) {
// return modal('Folder Creation Failed', typeof e === 'string' ? e : e.message, {
return modal ( 'Folder Creation Failed' , typeof e === 'string' ? e : e.message , {
// label: 'Close',
label : 'Close' ,
// fn: async () => {}
fn : async ( ) = > { }
// }, null)
} , null )
// }
}
// }
}
const deletePath = async ( path : string ) = > {
const deletePath = async ( path : string ) = > {
const filesProvider = fileSystem . provider . provider
if ( filesProvider . isReadOnly ( path ) ) {
if ( filesProvider . isReadOnly ( path ) ) {
return toast ( 'cannot delete file. ' + name + ' is a read only explorer' )
return toast ( 'cannot delete file. ' + name + ' is a read only explorer' )
}
}
@ -322,35 +324,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
// }
// }
// }
// }
// const removePath = (path: string, files: File[]): File[] => {
// return files.map(file => {
// if (file.path === path) {
// return null
// } else if (file.child) {
// const childFiles = removePath(path, file.child)
// file.child = childFiles.filter(file => file)
// return file
// } else {
// return file
// }
// })
// }
// const folderAdded = async (folderPath: string) => {
// const pathArr = folderPath.split('/')
// const expandPath = pathArr.map((path, index) => {
// return [...pathArr.slice(0, index)].join('/')
// }).filter(path => path && (path !== props.name))
// const files = await fetchDirectoryContent(props.name)
// setState(prevState => {
// const uniquePaths = [...new Set([...prevState.expandPath, ...expandPath])]
// return { ...prevState, files, expandPath: uniquePaths }
// })
// }
const fileExternallyChanged = ( path : string , file : { content : string } ) = > {
const fileExternallyChanged = ( path : string , file : { content : string } ) = > {
const config = registry . get ( 'config' ) . api
const config = registry . get ( 'config' ) . api
const editor = registry . get ( 'editor' ) . api
const editor = registry . get ( 'editor' ) . api
@ -369,23 +342,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
}
}
// const fileRemoved = (filePath) => {
// const files = removePath(filePath, state.files)
// const updatedFiles = files.filter(file => file)
// setState(prevState => {
// return { ...prevState, files: updatedFiles }
// })
// }
// const fileRenamed = async () => {
// const files = await fetchDirectoryContent(props.name)
// setState(prevState => {
// return { ...prevState, files, expandPath: [...prevState.expandPath] }
// })
// }
// register to event of the file provider
// register to event of the file provider
// files.event.register('fileRenamed', fileRenamed)
// files.event.register('fileRenamed', fileRenamed)
const fileRenamedError = ( error : string ) = > {
const fileRenamedError = ( error : string ) = > {
@ -632,7 +588,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const handleClickFile = ( path : string ) = > {
const handleClickFile = ( path : string ) = > {
console . log ( 'path: ' , path )
state . fileManager . open ( path )
state . fileManager . open ( path )
setState ( prevState = > {
setState ( prevState = > {
return { . . . prevState , focusElement : [ { key : path , type : 'file' } ] }
return { . . . prevState , focusElement : [ { key : path , type : 'file' } ] }
@ -655,6 +610,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
if ( ! state . expandPath . includes ( path ) ) {
if ( ! state . expandPath . includes ( path ) ) {
expandPath = [ . . . new Set ( [ . . . state . expandPath , path ] ) ]
expandPath = [ . . . new Set ( [ . . . state . expandPath , path ] ) ]
resolveDirectory ( fileSystem . provider . provider , path ) ( dispatch )
} else {
} else {
expandPath = [ . . . new Set ( state . expandPath . filter ( key = > key && ( typeof key === 'string' ) && ! key . startsWith ( path ) ) ) ]
expandPath = [ . . . new Set ( state . expandPath . filter ( key = > key && ( typeof key === 'string' ) && ! key . startsWith ( path ) ) ) ]
}
}
@ -662,7 +618,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
setState ( prevState = > {
setState ( prevState = > {
return { . . . prevState , focusElement : [ { key : path , type : 'folder' } ] , expandPath }
return { . . . prevState , focusElement : [ { key : path , type : 'folder' } ] , expandPath }
} )
} )
resolveDirectory ( fileSystem . provider . provider , path ) ( dispatch )
}
}
}
}
@ -723,8 +678,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
} , null )
} , null )
} else {
} else {
if ( state . focusEdit . isNew ) {
if ( state . focusEdit . isNew ) {
// state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content))
state . focusEdit . type === 'file' ? createNewFile ( joinPath ( parentFolder , content ) ) : createNewFolder ( joinPath ( parentFolder , content ) )
createNewFile ( joinPath ( parentFolder , content ) )
removeInputField ( fileSystem . provider . provider , parentFolder ) ( dispatch )
removeInputField ( fileSystem . provider . provider , parentFolder ) ( dispatch )
} else {
} else {
const oldPath : string = state . focusEdit . element
const oldPath : string = state . focusEdit . element
@ -845,12 +799,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
} }
>
>
{
{
file . child ? < TreeView id = { ` treeView ${ file . path } ` } key = { index } > {
file . child ? < TreeView id = { ` treeView ${ file . path } ` } key = { ` treeView ${ file . path } ` } > {
Object . keys ( file . child ) . map ( ( key , index ) = > {
Object . keys ( file . child ) . map ( ( key , index ) = > {
return renderFiles ( file . child [ key ] , index )
return renderFiles ( file . child [ key ] , index )
} )
} )
}
}
< / TreeView > : < TreeView id = { ` treeView ${ file . path } ` } key = { index } / >
< / TreeView > : < TreeView id = { ` treeView ${ file . path } ` } key = { ` treeView ${ file . path } ` } / >
}
}
< / TreeViewItem >
< / TreeViewItem >
)
)
@ -858,7 +812,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
return (
return (
< TreeViewItem
< TreeViewItem
id = { ` treeViewItem ${ file . path } ` }
id = { ` treeViewItem ${ file . path } ` }
key = { index }
key = { ` treeView ${ file . path } ` }
label = { label ( file ) }
label = { label ( file ) }
onClick = { ( e ) = > {
onClick = { ( e ) = > {
e . stopPropagation ( )
e . stopPropagation ( )