Change: show loaded and total

This commit is contained in:
eight 2019-10-04 19:46:56 +08:00
parent 1b02c5b85b
commit d88bd092e1
2 changed files with 9 additions and 12 deletions

View File

@ -10,7 +10,7 @@ const sync = (() => {
const status = {
state: 'disconnected',
syncing: false,
syncTarget: null,
progress: null,
currentDriveName: null
};
let currentDrive;
@ -73,14 +73,14 @@ const sync = (() => {
getStatus: () => status
};
function onProgress(type, change) {
if (type === 'syncStart') {
function onProgress(e) {
if (e.phase === 'start') {
status.syncing = true;
} else if (type === 'syncEnd') {
} else if (e.phase === 'end') {
status.syncing = false;
status.syncTarget = null;
status.progress = null;
} else {
status.syncTarget = [type, change];
status.progress = e;
}
emitStatusChange();
}

View File

@ -117,12 +117,9 @@ document.onclick = e => {
function getStatusText() {
// FIXME: i18n
if (status.syncing) {
if (status.syncTarget) {
const [type, change] = status.syncTarget;
if (type === 'syncPull') {
return `pulling data ${change._id}`;
}
return `pushing data ${change._id}`;
if (status.progress) {
const {phase, loaded, total} = status.syncTarget;
return `${phase}ing style ${loaded + 1} of ${total}`;
}
return 'syncing...';
}