fix: show correct sync status

This commit is contained in:
Baptiste Grob
2020-09-17 14:27:53 +02:00
parent 6f8543b6e5
commit 19a9f57bed
4 changed files with 29 additions and 26 deletions

View File

@@ -8,20 +8,13 @@ export class StatusManager {
private statuses: FooterStatus[] = [] private statuses: FooterStatus[] = []
private observers: StatusCallback[] = [] private observers: StatusCallback[] = []
statusFromString(string: string) {
return {string: string};
}
replaceStatusWithString(status: FooterStatus, string: string) { replaceStatusWithString(status: FooterStatus, string: string) {
this.removeStatus(status); this.removeStatus(status);
return this.addStatusFromString(string); return this.addStatusFromString(string);
} }
addStatusFromString(string: string) { addStatusFromString(string: string) {
return this.addStatus(this.statusFromString(string)); const status = { string };
}
addStatus(status: FooterStatus) {
this.statuses.push(status); this.statuses.push(status);
this.notifyObservers(); this.notifyObservers();
return status; return status;
@@ -33,7 +26,20 @@ export class StatusManager {
return undefined; return undefined;
} }
getStatusString() { addStatusObserver(callback: StatusCallback) {
this.observers.push(callback);
return () => {
removeFromArray(this.observers, callback);
}
}
private notifyObservers() {
for(const observer of this.observers) {
observer(this.getStatusString());
}
}
private getStatusString() {
let result = ''; let result = '';
this.statuses.forEach((status, index) => { this.statuses.forEach((status, index) => {
if(index > 0) { if(index > 0) {
@@ -45,16 +51,4 @@ export class StatusManager {
return result; return result;
} }
notifyObservers() {
for(const observer of this.observers) {
observer(this.getStatusString());
}
}
addStatusObserver(callback: StatusCallback) {
this.observers.push(callback);
return () => {
removeFromArray(this.observers, callback);
}
}
} }

View File

@@ -118,7 +118,7 @@ class ApplicationViewCtrl extends PureViewCtrl {
if (!this.completedInitialSync) { if (!this.completedInitialSync) {
this.syncStatus = this.application!.getStatusService().replaceStatusWithString( this.syncStatus = this.application!.getStatusService().replaceStatusWithString(
this.syncStatus, this.syncStatus,
"Syncing..." "Syncing"
); );
} }
} else if (eventName === ApplicationEvent.CompletedFullSync) { } else if (eventName === ApplicationEvent.CompletedFullSync) {
@@ -203,9 +203,18 @@ class ApplicationViewCtrl extends PureViewCtrl {
this.syncStatus = this.application!.getStatusService().removeStatus(this.syncStatus); this.syncStatus = this.application!.getStatusService().removeStatus(this.syncStatus);
}, 2000); }, 2000);
} else if (stats.uploadTotalCount > 20) { } else if (stats.uploadTotalCount > 20) {
const completionPercentage = stats.uploadCompletionCount === 0
? 0
: stats.uploadCompletionCount / stats.uploadTotalCount;
const stringPercentage = completionPercentage.toLocaleString(
undefined,
{ style: 'percent' }
);
this.uploadSyncStatus = this.application!.getStatusService().replaceStatusWithString( this.uploadSyncStatus = this.application!.getStatusService().replaceStatusWithString(
this.uploadSyncStatus, this.uploadSyncStatus,
`Syncing ${stats.uploadCompletionCount}/${stats.uploadTotalCount} items...` `Syncing ${stats.uploadTotalCount} items (${stringPercentage} complete)`,
); );
} else { } else {
if (this.syncStatus) { if (this.syncStatus) {

4
package-lock.json generated
View File

@@ -10956,8 +10956,8 @@
"from": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad" "from": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad"
}, },
"snjs": { "snjs": {
"version": "github:standardnotes/snjs#9003251047822f4353bcb83ec4dca59d9aebb301", "version": "github:standardnotes/snjs#f922ede72a3e90984605048854dc20db8a88c790",
"from": "github:standardnotes/snjs#9003251047822f4353bcb83ec4dca59d9aebb301" "from": "github:standardnotes/snjs#f922ede72a3e90984605048854dc20db8a88c790"
}, },
"sockjs": { "sockjs": {
"version": "0.3.20", "version": "0.3.20",

View File

@@ -68,6 +68,6 @@
}, },
"dependencies": { "dependencies": {
"sncrypto": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad", "sncrypto": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad",
"snjs": "github:standardnotes/snjs#9003251047822f4353bcb83ec4dca59d9aebb301" "snjs": "github:standardnotes/snjs#f922ede72a3e90984605048854dc20db8a88c790"
} }
} }