mapcomplete/UI/PendingChanges.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-06-23 22:35:19 +00:00
import {UIElement} from "./UIElement";
import {State} from "../State";
import {UIEventSource} from "../Logic/UIEventSource";
2020-06-23 22:35:19 +00:00
export class PendingChanges extends UIElement {
private _pendingChangesCount: UIEventSource<number>;
private _isSaving: UIEventSource<boolean>;
constructor() {
super(State.state.changes.pendingChangesES);
this.ListenTo(State.state.changes.isSaving);
this.ListenTo(State.state.secondsTillChangesAreSaved);
this._pendingChangesCount = State.state.changes.pendingChangesES;
this._isSaving = State.state.changes.isSaving;
2020-07-18 22:13:45 +00:00
this.onClick(() => {
State.state.changes.uploadAll();
2020-07-18 22:13:45 +00:00
})
2020-06-23 22:35:19 +00:00
}
2020-07-20 22:07:04 +00:00
InnerRender(): string {
if (this._isSaving.data) {
return "<span class='alert'>Saving</span>";
}
if (this._pendingChangesCount.data == 0) {
return "";
}
var restingSeconds =State.state.secondsTillChangesAreSaved.data / 1000;
var dots = "";
while (restingSeconds > 0) {
dots += ".";
restingSeconds = restingSeconds - 1;
}
return "Saving "+this._pendingChangesCount.data;
}
2020-06-23 22:35:19 +00:00
}