Show directory content for new input

pull/668/head
ioedeveloper 4 years ago
parent e07b38f156
commit 0a5c9de9b2
  1. 29
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx

@ -33,7 +33,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
type: '', type: '',
isNew: false isNew: false
}, },
fileExternallyChanged: false fileExternallyChanged: false,
expandPath: []
}) })
useEffect(() => { useEffect(() => {
@ -427,9 +428,16 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
} else { } else {
const files = await resolveDirectory(path, state.files) const files = await resolveDirectory(path, state.files)
let expandPath = []
if (!state.expandPath.includes(path)) {
expandPath = [...state.expandPath, path]
} else {
expandPath = state.expandPath.filter(key => key !== path)
}
setState(prevState => { setState(prevState => {
return { ...prevState, focusElement: [{ key: path, type: 'folder' }], files } return { ...prevState, focusElement: [{ key: path, type: 'folder' }], files, expandPath }
}) })
} }
} }
@ -506,23 +514,27 @@ export const FileExplorer = (props: FileExplorerProps) => {
}) })
} }
const handleNewFileInput = (parentFolder?: string) => { const handleNewFileInput = async (parentFolder?: string) => {
if (!parentFolder) parentFolder = state.focusElement[0] ? state.focusElement[0].type === 'folder' ? state.focusElement[0].key : extractParentFromKey(state.focusElement[0].key) : name if (!parentFolder) parentFolder = state.focusElement[0] ? state.focusElement[0].type === 'folder' ? state.focusElement[0].key : extractParentFromKey(state.focusElement[0].key) : name
const files = addEmptyFile(parentFolder, state.files) let files = await resolveDirectory(parentFolder, state.files)
const expandPath = [...state.expandPath, parentFolder]
files = addEmptyFile(parentFolder, files)
setState(prevState => { setState(prevState => {
return { ...prevState, files } return { ...prevState, files, expandPath }
}) })
editModeOn(parentFolder + '/blank', 'file', true) editModeOn(parentFolder + '/blank', 'file', true)
} }
const handleNewFolderInput = (parentFolder?: string) => { const handleNewFolderInput = async (parentFolder?: string) => {
if (!parentFolder) parentFolder = state.focusElement[0] ? state.focusElement[0].type === 'folder' ? state.focusElement[0].key : extractParentFromKey(state.focusElement[0].key) : name if (!parentFolder) parentFolder = state.focusElement[0] ? state.focusElement[0].type === 'folder' ? state.focusElement[0].key : extractParentFromKey(state.focusElement[0].key) : name
else if (parentFolder.indexOf('.sol') !== -1) parentFolder = extractParentFromKey(parentFolder) else if (parentFolder.indexOf('.sol') !== -1) parentFolder = extractParentFromKey(parentFolder)
const files = addEmptyFolder(parentFolder, state.files) let files = await resolveDirectory(parentFolder, state.files)
const expandPath = [...state.expandPath, parentFolder]
files = addEmptyFolder(parentFolder, state.files)
setState(prevState => { setState(prevState => {
return { ...prevState, files } return { ...prevState, files, expandPath }
}) })
editModeOn(parentFolder + '/blank', 'folder', true) editModeOn(parentFolder + '/blank', 'folder', true)
} }
@ -569,6 +581,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
editable={state.focusEdit.element === file.path} editable={state.focusEdit.element === file.path}
onBlur={(value) => editModeOff(value)} onBlur={(value) => editModeOff(value)}
controlBehaviour={ state.ctrlKey } controlBehaviour={ state.ctrlKey }
expand={state.expandPath.includes(file.path)}
> >
{ {
file.child ? <TreeView id={`treeView${file.path}`} key={index}>{ file.child ? <TreeView id={`treeView${file.path}`} key={index}>{

Loading…
Cancel
Save