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

View File

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