From a00e0f233298320d9ecd97c07be87e47823d35de Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Mon, 26 Apr 2021 13:58:20 +0100 Subject: [PATCH] Expand externally loaded files --- libs/remix-ui/file-explorer/src/lib/file-explorer.tsx | 8 ++++++++ .../remix-ui/file-explorer/src/lib/reducers/fileSystem.ts | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index a83b81d044..83c8f422cc 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -132,6 +132,14 @@ export const FileExplorer = (props: FileExplorerProps) => { } }, [fileSystem.notification.message]) + useEffect(() => { + if (fileSystem.files.expandPath.length > 0) { + setState(prevState => { + return { ...prevState, expandPath: [...new Set([...prevState.expandPath, ...fileSystem.files.expandPath])] } + }) + } + }, [fileSystem.files.expandPath]) + useEffect(() => { if (state.focusEdit.element) { setTimeout(() => { diff --git a/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts b/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts index df4475108e..2e033a17bd 100644 --- a/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts +++ b/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts @@ -8,6 +8,7 @@ interface Action { export const fileSystemInitialState = { files: { files: [], + expandPath: [], workspaceName: null, blankPath: null, isRequesting: false, @@ -175,6 +176,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action files: { ...state.files, files: fileAdded(state.files.workspaceName, action.payload.path, state.files.files, action.payload.files), + expandPath: [...new Set([...state.files.expandPath, action.payload.path])], isRequesting: false, isSuccessful: true, error: null @@ -187,6 +189,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action files: { ...state.files, files: folderAdded(state.files.workspaceName, action.payload.path, state.files.files, action.payload.files), + expandPath: [...new Set([...state.files.expandPath, action.payload.path])], isRequesting: false, isSuccessful: true, error: null @@ -271,12 +274,12 @@ const removePath = (root, path: string, pathName, files) => { }, []) const prevFiles = _.get(files, _path) - prevFiles.child[pathName] && delete prevFiles.child[pathName] + prevFiles && prevFiles.child && prevFiles.child[pathName] && delete prevFiles.child[pathName] files = _.set(files, _path, { isDirectory: true, path, name: extractNameFromKey(path), - child: prevFiles.child + child: prevFiles ? prevFiles.child : {} }) return files