Skip to content

Commit

Permalink
fix: fix webdav first add error
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed May 10, 2024
1 parent 5d1c8e2 commit d9850b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/filehandle/FileLinkedList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class Node {
}
}

const UPDATE_KEY = 'update';

class FileLinkedList {
root: Node;

Expand All @@ -33,22 +35,31 @@ 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 {
this.current = new Node(handle, this.current, null);
}
}

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;
Expand Down
8 changes: 7 additions & 1 deletion src/filehandle/components/FileContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,20 @@ const FileContent: React.FC<IFileContentProps> = (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);
}
});
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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/filehandle/hooks/useFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function useFileSystem(): FileSystem {

useMemo(
() => fileLinked.current?.listener((directory) => update(directory)),
[fileLinked.current]
[fileLinked.current, webdavs]
);

useEffect(() => {
Expand Down Expand Up @@ -224,6 +224,7 @@ export function useFileSystem(): FileSystem {
}, [
current,
children,
webdavs,
fileLinked.current,
backgroundManager.current,
isBusy
Expand Down

0 comments on commit d9850b2

Please sign in to comment.