From d9850b20e875c82defe3c531c27b6742eb408be0 Mon Sep 17 00:00:00 2001 From: yuanyxh <15766118362@139.com> Date: Fri, 10 May 2024 14:39:08 +0800 Subject: [PATCH] fix: fix webdav first add error --- src/filehandle/FileLinkedList.ts | 17 ++++++++++++++--- src/filehandle/components/FileContent.tsx | 8 +++++++- src/filehandle/hooks/useFileSystem.ts | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/filehandle/FileLinkedList.ts b/src/filehandle/FileLinkedList.ts index 8df1fbd..75318bf 100644 --- a/src/filehandle/FileLinkedList.ts +++ b/src/filehandle/FileLinkedList.ts @@ -14,6 +14,8 @@ export class Node { } } +const UPDATE_KEY = 'update'; + class FileLinkedList { root: Node; @@ -33,15 +35,14 @@ class FileLinkedList { set current(val) { this._current = val; - this.event.emit('update', val.value); + this.event.emit(UPDATE_KEY, val.value); } listener(fn: (directory: DH) => any) { - return this.event.on('update', fn); + return this.event.on(UPDATE_KEY, fn); } inset(handle: DH) { - // TODO: When I enter Directory A, return to the directory before entering, and delete the A directory A. At this time, abnormal if (this.current.next && handle.name === this.current.next.value.name) { this.current = this.current.next; } else { @@ -49,6 +50,16 @@ class FileLinkedList { } } + unlink(handle: DH) { + const { next } = this.current; + + if (next && next.value === handle) { + this.current.next = null; + + this.event.emit(UPDATE_KEY, this.current.value); + } + } + fallback() { if (this.current.fallback) { this.current.fallback.next = this.current; diff --git a/src/filehandle/components/FileContent.tsx b/src/filehandle/components/FileContent.tsx index 19a10dc..5f4905b 100644 --- a/src/filehandle/components/FileContent.tsx +++ b/src/filehandle/components/FileContent.tsx @@ -358,7 +358,7 @@ const FileContent: React.FC = (props) => { async onOk() { try { let _webdavs = webdavs.slice(0); - selection.map((file) => { + _selection.map((file) => { if (file.remote) { _webdavs = _webdavs.filter((webdav) => webdav.name !== file.name); } @@ -366,6 +366,12 @@ const FileContent: React.FC = (props) => { setWebdavs(_webdavs); await Promise.all(names.map((name) => remove(name))); + + _selection.map( + (file) => + file.type === FileType.DIRECTORY && + fileLinked.unlink(file.handle as DH) + ); } catch (err) { error((err as Error).message); } diff --git a/src/filehandle/hooks/useFileSystem.ts b/src/filehandle/hooks/useFileSystem.ts index 79bc5a5..caec05d 100644 --- a/src/filehandle/hooks/useFileSystem.ts +++ b/src/filehandle/hooks/useFileSystem.ts @@ -104,7 +104,7 @@ export function useFileSystem(): FileSystem { useMemo( () => fileLinked.current?.listener((directory) => update(directory)), - [fileLinked.current] + [fileLinked.current, webdavs] ); useEffect(() => { @@ -224,6 +224,7 @@ export function useFileSystem(): FileSystem { }, [ current, children, + webdavs, fileLinked.current, backgroundManager.current, isBusy