From 67289ef4ce7e40557c9bf9a770940fa04beee86c Mon Sep 17 00:00:00 2001 From: Thang Vu <31528554+ThangHuuVu@users.noreply.github.com> Date: Sun, 4 Apr 2021 19:06:10 +0700 Subject: [PATCH] feat: reopen library menu on import from file (#3383) Co-authored-by: Thang Vu --- src/components/App.tsx | 2 ++ src/components/LayerUI.tsx | 4 ++-- src/data/json.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 8147d340..14df48cc 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -3624,7 +3624,9 @@ class App extends React.Component { ) { Library.importLibrary(file) .then(() => { + // Close and then open to get the libraries updated this.setState({ isLibraryOpen: false }); + this.setState({ isLibraryOpen: true }); }) .catch((error) => this.setState({ isLoading: false, errorMessage: error.message }), diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx index 0ad77681..27c7f5aa 100644 --- a/src/components/LayerUI.tsx +++ b/src/components/LayerUI.tsx @@ -142,9 +142,9 @@ const LibraryMenuItems = ({ onClick={() => { importLibraryFromJSON() .then(() => { - // Maybe we should close and open the menu so that the items get updated. - // But for now we just close the menu. + // Close and then open to get the libraries updated setAppState({ isLibraryOpen: false }); + setAppState({ isLibraryOpen: true }); }) .catch(muteFSAbortError) .catch((error) => { diff --git a/src/data/json.ts b/src/data/json.ts index 4ecaccb3..59ac5eb3 100644 --- a/src/data/json.ts +++ b/src/data/json.ts @@ -116,5 +116,5 @@ export const importLibraryFromJSON = async () => { extensions: [".json", ".excalidrawlib"], */ }); - Library.importLibrary(blob); + await Library.importLibrary(blob); };