From 1fff691b3f8f07557e24d062b1a276f7c2d26571 Mon Sep 17 00:00:00 2001 From: yuanyxh <15766118362@139.com> Date: Wed, 8 May 2024 14:17:31 +0800 Subject: [PATCH] fix: webdav file error --- src/filehandle/WebdavFile.ts | 1 + src/filehandle/components/FileContent.tsx | 16 +++++++- .../md_editor/component/MDEditor.tsx | 38 ++++++++++++------- src/store/useUserStore.ts | 6 +++ vite.config.ts | 2 +- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/filehandle/WebdavFile.ts b/src/filehandle/WebdavFile.ts index 483ee96..d778905 100644 --- a/src/filehandle/WebdavFile.ts +++ b/src/filehandle/WebdavFile.ts @@ -42,6 +42,7 @@ class WebdavFileSystemFileHandle implements FileSystemFileHandle { this.fullPath = fullPath; } + createSyncAccessHandle(): Promise { throw new Error('Method not implemented.'); } diff --git a/src/filehandle/components/FileContent.tsx b/src/filehandle/components/FileContent.tsx index 2f20a53..0cf655e 100644 --- a/src/filehandle/components/FileContent.tsx +++ b/src/filehandle/components/FileContent.tsx @@ -267,6 +267,8 @@ interface IFileContentProps { const FileContent: React.FC = (props) => { const { modal, message } = App.useApp(); + const { webdavs, setWebdavs } = useUserStore(); + const { current, children, @@ -361,7 +363,11 @@ const FileContent: React.FC = (props) => { }; const handleDeleteFile = () => { - const names = selection.slice(0).map((file) => file.name); + const _selection = selection.slice(0); + + const names = _selection + .filter((file) => !file.remote) + .map((file) => file.name); modal.confirm({ title: '温馨提示', @@ -369,6 +375,14 @@ const FileContent: React.FC = (props) => { content: '您确认要删除这个文件吗?', async onOk() { try { + let _webdavs = webdavs.slice(0); + selection.map((file) => { + if (file.remote) { + _webdavs = _webdavs.filter((webdav) => webdav.name !== file.name); + } + }); + setWebdavs(_webdavs); + await Promise.all(names.map((name) => remove(name))); } catch (err) { message.error((err as Error).message); diff --git a/src/filehandle/md_editor/component/MDEditor.tsx b/src/filehandle/md_editor/component/MDEditor.tsx index cebaae8..1bf8a7b 100644 --- a/src/filehandle/md_editor/component/MDEditor.tsx +++ b/src/filehandle/md_editor/component/MDEditor.tsx @@ -99,6 +99,8 @@ const MDEditor = forwardRef( const editorRef = useRef(); const mdStringRef = useRef(''); + const creatingRef = useRef(false); + useImperativeHandle(ref, () => ({ getMarkdown() { return editorRef.current ? getMDString(editorRef.current.ctx) : ''; @@ -106,19 +108,29 @@ const MDEditor = forwardRef( })); useMemo(() => { - (async () => { - if (editorRef.current) { - await editorRef.current.destroy(true); - } - - createMDEditor(editorContainerRef.current!, markdown, onUpdate).then( - (value) => { - editorRef.current = value; - mdStringRef.current = markdown; - onChanged(false); - } - ); - })(); + if (creatingRef.current) { + return void 0; + } + + if (editorRef.current) { + editorRef.current.destroy(true); + } + + creatingRef.current = true; + + createMDEditor(editorContainerRef.current!, markdown, onUpdate) + .then((value) => { + editorRef.current = value; + mdStringRef.current = markdown; + onChanged(false); + }) + .finally(() => { + creatingRef.current = false; + }); + + return () => { + editorRef.current?.destroy(true); + }; }, [markdown]); function onUpdate(md: string) { diff --git a/src/store/useUserStore.ts b/src/store/useUserStore.ts index 2896fff..9ac6f7d 100644 --- a/src/store/useUserStore.ts +++ b/src/store/useUserStore.ts @@ -15,6 +15,7 @@ export interface UserState { export interface UserActions { addWebdav(webdav: WebdavInfo): void; + setWebdavs(webdavs: WebdavInfo[]): void; } const useAppStore = create((set) => ({ @@ -29,6 +30,11 @@ const useAppStore = create((set) => ({ return webdavs; }); + }, + setWebdavs(webdavs) { + set({ webdavs }); + + setStorage('user', webdavs); } })); diff --git a/vite.config.ts b/vite.config.ts index c85a47d..87376c9 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -169,7 +169,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { cors: true, proxy: { '/api': { - target: '', + target: 'http://8.222.131.201:8362', changeOrigin: true, ws: true, rewrite: (path) => path.replace(/^\/api/, 'notes')