fix(fe/panel_uploading): add delete button for stopped uploadings and create uploading files asap

This commit is contained in:
hexxa 2022-02-27 12:31:51 +08:00 committed by Hexxa
parent 662b06a94b
commit 73a6dfe4ae
3 changed files with 51 additions and 15 deletions

View file

@ -118,18 +118,30 @@ export class UploadingsPanel extends React.Component<Props, State, {}> {
case UploadState.Error: case UploadState.Error:
rightCell = ( rightCell = (
<div className="item-op"> <div className="item-op">
<span className="badge white-font red0-bg"> <span className="badge white-font red0-bg margin-r-m">
{this.props.msg.pkg.get("state.error")} {this.props.msg.pkg.get("state.error")}
</span> </span>
<button
onClick={() => this.deleteUpload(uploading.filePath)}
className="float-input"
>
{this.props.msg.pkg.get("browser.delete")}
</button>
</div> </div>
); );
break; break;
case UploadState.Stopped: case UploadState.Stopped:
rightCell = ( rightCell = (
<div className="item-op"> <div className="item-op">
<span className="badge yellow0-font black-bg"> <span className="badge yellow0-font black-bg margin-r-m">
{this.props.msg.pkg.get("state.stopped")} {this.props.msg.pkg.get("state.stopped")}
</span> </span>
<button
onClick={() => this.deleteUpload(uploading.filePath)}
className="float-input"
>
{this.props.msg.pkg.get("browser.delete")}
</button>
</div> </div>
); );
break; break;

View file

@ -141,7 +141,7 @@ export class ChunkUploader {
return { return {
filePath, filePath,
uploaded: uploadResp.data.uploaded, uploaded: uploadResp.data.uploaded,
state: UploadState.Ready, state: UploadState.Created,
err: "", err: "",
}; };
} else if (isFatalErr(uploadResp)) { } else if (isFatalErr(uploadResp)) {
@ -174,7 +174,7 @@ export class ChunkUploader {
? { ? {
filePath, filePath,
uploaded: uploadStatusResp.data.uploaded, uploaded: uploadStatusResp.data.uploaded,
state: UploadState.Ready, state: UploadState.Created,
err: `retrying, error: ${JSON.stringify(uploadResp.data)}`, err: `retrying, error: ${JSON.stringify(uploadResp.data)}`,
} }
: { : {

View file

@ -41,13 +41,12 @@ export class UploadMgr {
} }
const infos = this.infos.valueSeq().toArray(); const infos = this.infos.valueSeq().toArray();
// create files at first to persist uploading info
for (let i = 0; i < this.infos.size; i++) { for (let i = 0; i < this.infos.size; i++) {
const info = infos[i]; const info = infos[i];
if ( if (info.state === UploadState.Ready) {
info.state === UploadState.Ready ||
info.state === UploadState.Created
) {
this.infos = this.infos.set(info.filePath, { this.infos = this.infos.set(info.filePath, {
...info, ...info,
state: UploadState.Uploading, state: UploadState.Uploading,
@ -59,8 +58,32 @@ export class UploadMgr {
filePath: info.filePath, filePath: info.filePath,
size: info.size, size: info.size,
uploaded: info.uploaded, uploaded: info.uploaded,
created: info.uploaded > 0 || info.state === UploadState.Created, created: false,
}); });
return;
}
}
// start uploading if all files are created
for (let i = 0; i < this.infos.size; i++) {
const info = infos[i];
if (info.state === UploadState.Created) {
this.infos = this.infos.set(info.filePath, {
...info,
state: UploadState.Uploading,
});
this.worker.postMessage({
kind: syncReqKind,
file: info.file,
filePath: info.filePath,
size: info.size,
uploaded: info.uploaded,
created: true,
});
break; break;
} }
} }
@ -201,15 +224,16 @@ export class UploadMgr {
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(), true);
} else { } else {
// this avoids overwriting Stopped/Error state
const state =
entry.state === UploadState.Stopped ||
entry.state === UploadState.Error
? entry.state
: infoResp.state;
this.infos = this.infos.set(infoResp.filePath, { this.infos = this.infos.set(infoResp.filePath, {
...entry, ...entry,
uploaded: infoResp.uploaded, uploaded: infoResp.uploaded,
state: state: state,
// this avoids overwriting Stopped/Error state
entry.state === UploadState.Stopped ||
entry.state === UploadState.Error
? UploadState.Stopped
: infoResp.state,
}); });
this.statusCb(this.infos.toMap(), false); this.statusCb(this.infos.toMap(), false);
} }