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