fix(uploader): don't need to refresh files list after uploading status changing

This commit is contained in:
hexxa 2022-03-11 15:25:21 +08:00 committed by Hexxa
parent 8c508c517f
commit 73f3cb2da6
2 changed files with 11 additions and 23 deletions

View file

@ -138,8 +138,7 @@ export class FilesPanel extends React.Component<Props, State, {}> {
}; };
updateProgress = async ( updateProgress = async (
infos: Map<string, UploadEntry>, infos: Map<string, UploadEntry>
refresh: boolean
) => { ) => {
updater().setUploads(infos); updater().setUploads(infos);
let errCount = 0; let errCount = 0;
@ -157,16 +156,6 @@ export class FilesPanel extends React.Component<Props, State, {}> {
this.props.update(updater().updateLogin); this.props.update(updater().updateLogin);
this.props.update(updater().updateUploadingsInfo); this.props.update(updater().updateUploadingsInfo);
} }
if (refresh) {
const status = await updater().setItems(this.props.filesInfo.dirPath);
if (status !== "") {
alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status));
return;
}
}
this.props.update(updater().updateFilesInfo);
this.props.update(updater().updateUploadingsInfo);
}; };
addUploads = (event: React.ChangeEvent<HTMLInputElement>) => { addUploads = (event: React.ChangeEvent<HTMLInputElement>) => {

View file

@ -26,8 +26,7 @@ export class UploadMgr {
private worker: IWorker; private worker: IWorker;
private infos = OrderedMap<string, UploadEntry>(); private infos = OrderedMap<string, UploadEntry>();
private statusCb = ( private statusCb = (
infos: Map<string, UploadEntry>, infos: Map<string, UploadEntry>
refresh: boolean
): void => { }; ): void => { };
constructor(worker: IWorker) { constructor(worker: IWorker) {
@ -104,7 +103,7 @@ export class UploadMgr {
// TODO: change it to observer pattern // TODO: change it to observer pattern
// so that it can be observed by multiple components // so that it can be observed by multiple components
setStatusCb = ( setStatusCb = (
cb: (infos: Map<string, UploadEntry>, refresh: boolean) => void cb: (infos: Map<string, UploadEntry>) => void
) => { ) => {
this.statusCb = cb; this.statusCb = cb;
}; };
@ -156,7 +155,7 @@ export class UploadMgr {
} }
} }
this.statusCb(this.infos.toMap(), false); this.statusCb(this.infos.toMap());
return status; return status;
}; };
@ -173,7 +172,7 @@ export class UploadMgr {
status = errUploadMgr; status = errUploadMgr;
} }
this.statusCb(this.infos.toMap(), false); this.statusCb(this.infos.toMap());
return status; return status;
}; };
@ -184,7 +183,7 @@ export class UploadMgr {
} }
this.infos = this.infos.delete(filePath); this.infos = this.infos.delete(filePath);
this.statusCb(this.infos.toMap(), false); this.statusCb(this.infos.toMap());
return ""; return "";
}; };
@ -213,7 +212,7 @@ export class UploadMgr {
ErrorLogger().error(`respHandler: entry not found ${errResp.err}`); ErrorLogger().error(`respHandler: entry not found ${errResp.err}`);
} }
this.statusCb(this.infos.toMap(), false); this.statusCb(this.infos.toMap());
break; break;
case uploadInfoKind: case uploadInfoKind:
const infoResp = resp as UploadInfoResp; const infoResp = resp as UploadInfoResp;
@ -222,7 +221,7 @@ export class UploadMgr {
if (entry != null) { if (entry != null) {
if (infoResp.uploaded === entry.size) { if (infoResp.uploaded === entry.size) {
this.infos = this.infos.delete(infoResp.filePath); this.infos = this.infos.delete(infoResp.filePath);
this.statusCb(this.infos.toMap(), true); this.statusCb(this.infos.toMap());
} else { } else {
// this avoids overwriting Stopped/Error state // this avoids overwriting Stopped/Error state
const state = const state =
@ -235,7 +234,7 @@ export class UploadMgr {
uploaded: infoResp.uploaded, uploaded: infoResp.uploaded,
state: state, state: state,
}); });
this.statusCb(this.infos.toMap(), false); this.statusCb(this.infos.toMap());
} }
} else { } else {
ErrorLogger().error( ErrorLogger().error(