More refactoring, stuff kindoff works

This commit is contained in:
Pieter Vander Vennet 2021-06-12 02:58:32 +02:00
parent 62f471df1e
commit 3943100e54
52 changed files with 635 additions and 1010 deletions

View file

@ -1,35 +1,47 @@
import {UIEventSource} from "../../Logic/UIEventSource";
import {UIElement} from "../UIElement";
import Translations from "../i18n/Translations";
import UserDetails, {OsmConnection} from "../../Logic/Osm/OsmConnection";
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
import BaseUIElement from "../BaseUIElement";
import Toggle from "../Input/Toggle";
export class SaveButton extends UIElement {
private readonly _value: UIEventSource<any>;
private readonly _friendlyLogin: UIElement;
private readonly _userDetails: UIEventSource<UserDetails>;
private readonly _element: BaseUIElement;
constructor(value: UIEventSource<any>, osmConnection: OsmConnection) {
super(value);
this._userDetails = osmConnection?.userDetails;
if(value === undefined){
if (value === undefined) {
throw "No event source for savebutton, something is wrong"
}
this._value = value;
this._friendlyLogin = Translations.t.general.loginToStart.Clone()
const pleaseLogin = Translations.t.general.loginToStart.Clone()
.SetClass("login-button-friendly")
.onClick(() => osmConnection?.AttemptLogin())
const isSaveable = value.map(v => v !== false && (v ?? "") !== "")
const saveEnabled = Translations.t.general.save.Clone().SetClass(`btn`);
const saveDisabled = Translations.t.general.save.Clone().SetClass(`btn btn-disabled`);
const save = new Toggle(
saveEnabled,
saveDisabled,
isSaveable
)
this._element = new Toggle(
save
, pleaseLogin,
osmConnection?.userDetails?.map(userDetails => userDetails.loggedIn) ?? new UIEventSource<any>(false)
)
}
InnerRender() {
if(this._userDetails != undefined && !this._userDetails.data.loggedIn){
return this._friendlyLogin;
}
let inactive_class = ''
if (this._value.data === false || (this._value.data ?? "") === "") {
inactive_class = "btn-disabled";
}
return Translations.t.general.save.Clone().SetClass(`btn ${inactive_class}`);
InnerRender(): BaseUIElement {
return this._element
}
}