Explorar el Código

:art: fix https://github.com/siyuan-note/siyuan/issues/10517

Vanessa hace 1 año
padre
commit
fa1e63302f
Se han modificado 1 ficheros con 72 adiciones y 66 borrados
  1. 72 66
      app/src/menus/navigation.ts

+ 72 - 66
app/src/menus/navigation.ts

@@ -638,75 +638,81 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
 };
 
 export const genImportMenu = (notebookId: string, pathString: string) => {
-    if (!window.siyuan.config.readonly) {
-        /// #if !BROWSER
-        const importstdmd = (label: string, isDoc?: boolean) => {
-            return {
-                icon: isDoc ? "iconMarkdown" : "iconFolder",
-                label,
-                click: async () => {
-                    let filters: FileFilter[] = [];
-                    if (isDoc) {
-                        filters = [{name: "Markdown", extensions: ["md", "markdown"]}];
-                    }
-                    const localPath = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
-                        cmd: "showOpenDialog",
-                        defaultPath: window.siyuan.config.system.homeDir,
-                        filters,
-                        properties: [isDoc ? "openFile" : "openDirectory"],
-                    });
-                    if (localPath.filePaths.length === 0) {
-                        return;
-                    }
-                    fetchPost("/api/import/importStdMd", {
-                        notebook: notebookId,
-                        localPath: localPath.filePaths[0],
-                        toPath: pathString,
-                    });
+    if (window.siyuan.config.readonly) {
+        return;
+    }
+    const reloadDocTree = () => {
+        let files;
+        /// #if MOBILE
+        files = window.siyuan.mobile.files;
+        /// #else
+        files = (getDockByType("file").data["file"] as Files);
+        /// #endif
+        const liElement = files.element.querySelector(`[data-path="${pathString}"]`);
+        const toggleElement = liElement.querySelector(".b3-list-item__arrow--open");
+        if (toggleElement) {
+            toggleElement.classList.remove("b3-list-item__arrow--open");
+            liElement.nextElementSibling?.remove();
+        }
+        files.getLeaf(liElement, notebookId);
+        window.siyuan.menus.menu.remove();
+    }
+    /// #if !BROWSER
+    const importstdmd = (label: string, isDoc?: boolean) => {
+        return {
+            icon: isDoc ? "iconMarkdown" : "iconFolder",
+            label,
+            click: async () => {
+                let filters: FileFilter[] = [];
+                if (isDoc) {
+                    filters = [{name: "Markdown", extensions: ["md", "markdown"]}];
                 }
-            };
+                const localPath = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
+                    cmd: "showOpenDialog",
+                    defaultPath: window.siyuan.config.system.homeDir,
+                    filters,
+                    properties: [isDoc ? "openFile" : "openDirectory"],
+                });
+                if (localPath.filePaths.length === 0) {
+                    return;
+                }
+                fetchPost("/api/import/importStdMd", {
+                    notebook: notebookId,
+                    localPath: localPath.filePaths[0],
+                    toPath: pathString,
+                }, () => {
+                    reloadDocTree();
+                });
+            }
         };
-        /// #endif
-        window.siyuan.menus.menu.append(new MenuItem({
-            icon: "iconDownload",
-            label: window.siyuan.languages.import,
-            submenu: [{
-                icon: "iconSiYuan",
-                label: 'SiYuan .sy.zip<input class="b3-form__upload" type="file" accept="application/zip">',
-                bind: (element) => {
-                    element.querySelector(".b3-form__upload").addEventListener("change", (event: InputEvent & {
-                        target: HTMLInputElement
-                    }) => {
-                        const formData = new FormData();
-                        formData.append("file", event.target.files[0]);
-                        formData.append("notebook", notebookId);
-                        formData.append("toPath", pathString);
-                        fetchPost("/api/import/importSY", formData, () => {
-                            let files;
-                            /// #if MOBILE
-                            files = window.siyuan.mobile.files;
-                            /// #else
-                            files = (getDockByType("file").data["file"] as Files);
-                            /// #endif
-                            const liElement = files.element.querySelector(`[data-path="${pathString}"]`);
-                            const toggleElement = liElement.querySelector(".b3-list-item__arrow--open");
-                            if (toggleElement) {
-                                toggleElement.classList.remove("b3-list-item__arrow--open");
-                                liElement.nextElementSibling?.remove();
-                            }
-                            files.getLeaf(liElement, notebookId);
-                            window.siyuan.menus.menu.remove();
-                        });
+    };
+    /// #endif
+    window.siyuan.menus.menu.append(new MenuItem({
+        icon: "iconDownload",
+        label: window.siyuan.languages.import,
+        submenu: [{
+            icon: "iconSiYuan",
+            label: 'SiYuan .sy.zip<input class="b3-form__upload" type="file" accept="application/zip">',
+            bind: (element) => {
+                element.querySelector(".b3-form__upload").addEventListener("change", (event: InputEvent & {
+                    target: HTMLInputElement
+                }) => {
+                    const formData = new FormData();
+                    formData.append("file", event.target.files[0]);
+                    formData.append("notebook", notebookId);
+                    formData.append("toPath", pathString);
+                    fetchPost("/api/import/importSY", formData, () => {
+                        reloadDocTree();
                     });
-                }
-            },
-                /// #if !BROWSER
-                importstdmd("Markdown " + window.siyuan.languages.doc, true),
-                importstdmd("Markdown " + window.siyuan.languages.folder)
-                /// #endif
-            ],
-        }).element);
-    }
+                });
+            }
+        },
+            /// #if !BROWSER
+            importstdmd("Markdown " + window.siyuan.languages.doc, true),
+            importstdmd("Markdown " + window.siyuan.languages.folder)
+            /// #endif
+        ],
+    }).element);
 };
 
 export const sortMenu = (type: "notebooks" | "notebook", sortMode: number, clickEvent: (sort: number) => void) => {