mapcomplete/UI/BigComponents/ThemeIntroductionPanel.ts

61 lines
2 KiB
TypeScript
Raw Normal View History

import Locale from "../i18n/Locale";
import {UIElement} from "../UIElement";
import State from "../../State";
import Combine from "../Base/Combine";
import LanguagePicker from "../LanguagePicker";
import Translations from "../i18n/Translations";
2021-01-07 04:50:12 +01:00
import {VariableUiElement} from "../Base/VariableUIElement";
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
import {UIEventSource} from "../../Logic/UIEventSource";
2021-01-07 04:50:12 +01:00
export default class ThemeIntroductionPanel extends UIElement {
private languagePicker: UIElement;
2021-01-07 04:50:12 +01:00
private readonly loginStatus: UIElement;
private _layout: UIEventSource<LayoutConfig>;
constructor() {
super(State.state.osmConnection.userDetails);
this.ListenTo(Locale.language);
2020-11-11 16:23:49 +01:00
this.languagePicker = LanguagePicker.CreateLanguagePicker(State.state.layoutToUse.data.language, Translations.t.general.pickLanguage);
this._layout = State.state.layoutToUse;
this.ListenTo(State.state.layoutToUse);
const plzLogIn =
2020-11-11 16:23:49 +01:00
Translations.t.general.loginWithOpenStreetMap
.onClick(() => {
State.state.osmConnection.AttemptLogin()
});
const welcomeBack = Translations.t.general.welcomeBack;
2021-01-07 04:50:12 +01:00
this.loginStatus = new VariableUiElement(
State.state.osmConnection.userDetails.map(
userdetails => {
if (State.state.featureSwitchUserbadge.data) {
return "";
}
return (userdetails.loggedIn ? welcomeBack : plzLogIn).Render();
2021-01-07 04:50:12 +01:00
}
)
)
}
InnerRender(): string {
const layout : LayoutConfig = this._layout.data;
return new Combine([
layout.description,
"<br/><br/>",
2021-01-07 04:50:12 +01:00
this.loginStatus,
layout.descriptionTail,
"<br/>",
this.languagePicker,
...layout.CustomCodeSnippets()
]).Render()
}
2020-11-24 14:36:43 +01:00
}