Butchering the UI framework

This commit is contained in:
Pieter Vander Vennet 2021-06-10 01:36:20 +02:00
parent 8d404b1ba9
commit 6415e195d1
90 changed files with 1012 additions and 3101 deletions

View file

@ -44,16 +44,14 @@ export default class AttributionPanel extends Combine {
const contribs = links.join(", ")
if (hiddenCount == 0) {
return Translations.t.general.attribution.mapContributionsBy.Subs({
contributors: contribs
}).InnerRender()
})
} else {
return Translations.t.general.attribution.mapContributionsByAndHidden.Subs({
contributors: contribs,
hiddenCount: hiddenCount
}).InnerRender();
});
}

View file

@ -4,10 +4,11 @@ import Translations from "../i18n/Translations";
import State from "../../State";
import {UIEventSource} from "../../Logic/UIEventSource";
import BaseLayer from "../../Models/BaseLayer";
import BaseUIElement from "../BaseUIElement";
export default class BackgroundSelector extends UIElement {
private _dropdown: UIElement;
private _dropdown: BaseUIElement;
private readonly _availableLayers: UIEventSource<BaseLayer[]>;
constructor() {
@ -31,8 +32,8 @@ export default class BackgroundSelector extends UIElement {
this._dropdown = new DropDown(Translations.t.general.backgroundMap, baseLayers, State.state.backgroundLayer);
}
InnerRender(): string {
return this._dropdown.Render();
InnerRender(): BaseUIElement {
return this._dropdown;
}
}

View file

@ -80,8 +80,8 @@ export default class FullWelcomePaneWithTabs extends UIElement {
.ListenTo(userDetails);
}
InnerRender(): string {
return this._component.Render();
InnerRender(): UIElement {
return this._component;
}

View file

@ -2,7 +2,7 @@ import {UIEventSource} from "../../Logic/UIEventSource";
import {UIElement} from "../UIElement";
import {VariableUiElement} from "../Base/VariableUIElement";
import State from "../../State";
import CheckBox from "../Input/CheckBox";
import Toggle from "../Input/Toggle";
import Combine from "../Base/Combine";
import {FixedUiElement} from "../Base/FixedUiElement";
import Translations from "../i18n/Translations";
@ -65,7 +65,7 @@ export default class LayerSelection extends UIElement {
}))
const style = "display:flex;align-items:center;"
const styleWhole = "display:flex; flex-wrap: wrap"
this._checkboxes.push(new CheckBox(
this._checkboxes.push(new Toggle(
new Combine([new Combine([icon, name]).SetStyle(style), zoomStatus])
.SetStyle(styleWhole),
new Combine([new Combine([iconUnselected, "<del>", name, "</del>"]).SetStyle(style), zoomStatus])

View file

@ -1,4 +1,3 @@
import {UIElement} from "../UIElement";
import {VariableUiElement} from "../Base/VariableUIElement";
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
import {AllKnownLayouts} from "../../Customizations/AllKnownLayouts";
@ -11,87 +10,93 @@ import * as personal from "../../assets/themes/personalLayout/personalLayout.jso
import Constants from "../../Models/Constants";
import LanguagePicker from "../LanguagePicker";
import IndexText from "./IndexText";
import BaseUIElement from "../BaseUIElement";
export default class MoreScreen extends UIElement {
private readonly _onMainScreen: boolean;
private _component: UIElement;
export default class MoreScreen extends Combine {
constructor(onMainScreen: boolean = false) {
super(State.state.locationControl);
this._onMainScreen = onMainScreen;
this.ListenTo(State.state.osmConnection.userDetails);
this.ListenTo(State.state.installedThemes);
super(MoreScreen.Init(onMainScreen, State.state));
}
InnerRender(): string {
private static Init(onMainScreen: boolean, state: State): BaseUIElement [] {
const tr = Translations.t.general.morescreen;
const els: UIElement[] = []
const themeButtons: UIElement[] = []
for (const layout of AllKnownLayouts.layoutsList) {
if (layout.id === personal.id) {
if (State.state.osmConnection.userDetails.data.csCount < Constants.userJourney.personalLayoutUnlock) {
continue;
}
}
themeButtons.push(this.createLinkButton(layout));
}
els.push(new VariableUiElement(
State.state.osmConnection.userDetails.map(userDetails => {
if (userDetails.csCount < Constants.userJourney.themeGeneratorReadOnlyUnlock) {
return new SubtleButton(null, tr.requestATheme, {url:"https://github.com/pietervdvn/MapComplete/issues", newTab: true}).Render();
}
return new SubtleButton(Svg.pencil_ui(), tr.createYourOwnTheme, {
url: "./customGenerator.html",
newTab: false
}).Render();
})
));
els.push(new Combine(themeButtons))
const customThemesNames = State.state.installedThemes.data ?? [];
if (customThemesNames.length > 0) {
els.push(Translations.t.general.customThemeIntro)
for (const installed of State.state.installedThemes.data) {
els.push(this.createLinkButton(installed.layout, installed.definition));
}
}
let intro: UIElement = tr.intro;
const themeButtonsElement = new Combine(els)
if (this._onMainScreen) {
let intro: BaseUIElement = tr.intro;
let themeButtonStyle = ""
let themeListStyle = ""
if (onMainScreen) {
intro = new Combine([
LanguagePicker.CreateLanguagePicker(Translations.t.index.title.SupportedLanguages())
.SetClass("absolute top-2 right-3"),
new IndexText()
])
themeButtons.map(e => e?.SetClass("h-32 min-h-32 max-h-32 overflow-ellipsis overflow-hidden"))
themeButtonsElement.SetClass("md:grid md:grid-flow-row md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-g4 gap-4")
themeButtonStyle = "h-32 min-h-32 max-h-32 overflow-ellipsis overflow-hidden"
themeListStyle = "md:grid md:grid-flow-row md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-g4 gap-4"
}
this._component = new Combine([
return[
intro,
themeButtonsElement,
MoreScreen.createOfficialThemesList(state, themeButtonStyle).SetClass(themeListStyle),
MoreScreen.createUnofficialThemeList(themeButtonStyle)?.SetClass(themeListStyle),
tr.streetcomplete.SetClass("block text-base mx-10 my-3 mb-10")
]);
return this._component.Render();
];
}
private static createUnofficialThemeList(buttonClass: string): BaseUIElement{
const customThemes = State.state.installedThemes.data ?? [];
const els : BaseUIElement[] = []
if (customThemes.length > 0) {
els.push(Translations.t.general.customThemeIntro)
const customThemesElement = new Combine(
customThemes.map(theme => MoreScreen.createLinkButton(theme.layout, theme.definition)?.SetClass(buttonClass))
)
els.push(customThemesElement)
}
return new Combine(els)
}
private createLinkButton(layout: LayoutConfig, customThemeDefinition: string = undefined) {
private static createOfficialThemesList(state: State, buttonClass: string): BaseUIElement {
let officialThemes = AllKnownLayouts.layoutsList
if (State.state.osmConnection.userDetails.data.csCount < Constants.userJourney.personalLayoutUnlock) {
officialThemes = officialThemes.filter(theme => theme.id !== personal.id)
}
let buttons = officialThemes.map((layout) => MoreScreen.createLinkButton(layout)?.SetClass(buttonClass))
let customGeneratorLink = MoreScreen.createCustomGeneratorButton(state)
buttons.splice(0, 0, customGeneratorLink);
return new Combine(buttons)
}
/*
* Returns either a link to the issue tracker or a link to the custom generator, depending on the achieved number of changesets
* */
private static createCustomGeneratorButton(state: State): VariableUiElement {
const tr = Translations.t.general.morescreen;
return new VariableUiElement(
state.osmConnection.userDetails.map(userDetails => {
if (userDetails.csCount < Constants.userJourney.themeGeneratorReadOnlyUnlock) {
return new SubtleButton(null, tr.requestATheme, {
url: "https://github.com/pietervdvn/MapComplete/issues",
newTab: true
});
}
return new SubtleButton(Svg.pencil_ui(), tr.createYourOwnTheme, {
url: "./customGenerator.html",
newTab: false
});
})
)
}
/**
* Creates a button linking to the given theme
* @param layout
* @param customThemeDefinition
* @private
*/
private static createLinkButton(layout: LayoutConfig, customThemeDefinition: string = undefined): BaseUIElement {
if (layout === undefined) {
return undefined;
}
@ -100,17 +105,14 @@ export default class MoreScreen extends UIElement {
return undefined;
}
if (layout.hideFromOverview) {
const pref = State.state.osmConnection.GetPreference("hidden-theme-" + layout.id + "-enabled");
this.ListenTo(pref);
if (pref.data !== "true") {
return undefined;
}
return undefined;
}
if (layout.id === State.state.layoutToUse.data?.id) {
return undefined;
}
const currentLocation = State.state.locationControl.data;
const currentLocation = State.state.locationControl;
let path = window.location.pathname;
// Path starts with a '/' and contains everything, e.g. '/dir/dir/page.html'
path = path.substr(0, path.lastIndexOf("/"));
@ -119,19 +121,23 @@ export default class MoreScreen extends UIElement {
path = "."
}
const params = `z=${currentLocation.zoom ?? 1}&lat=${currentLocation.lat ?? 0}&lon=${currentLocation.lon ?? 0}`
let linkText =
`${path}/${layout.id.toLowerCase()}.html?${params}`
let linkPrefix = `${path}/${layout.id.toLowerCase()}.html?`
let linkSuffix = ""
if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
linkText = `${path}/index.html?layout=${layout.id}&${params}`
linkPrefix = `${path}/index.html?layout=${layout.id}&`
}
if (customThemeDefinition) {
linkText = `${path}/index.html?userlayout=${layout.id}&${params}#${customThemeDefinition}`
linkPrefix = `${path}/index.html?userlayout=${layout.id}&`
linkSuffix = `#${customThemeDefinition}`
}
const linkText = currentLocation.map(currentLocation =>
`${linkPrefix}z=${currentLocation.zoom ?? 1}&lat=${currentLocation.lat ?? 0}&lon=${currentLocation.lon ?? 0}${linkSuffix}`)
let description = Translations.W(layout.shortDescription);
return new SubtleButton(layout.icon,
new Combine([
@ -144,4 +150,5 @@ export default class MoreScreen extends UIElement {
]), {url: linkText, newTab: false});
}
}

View file

@ -5,7 +5,7 @@ import {AllKnownLayouts} from "../../Customizations/AllKnownLayouts";
import Svg from "../../Svg";
import State from "../../State";
import Combine from "../Base/Combine";
import CheckBox from "../Input/CheckBox";
import Toggle from "../Input/Toggle";
import {SubtleButton} from "../Base/SubtleButton";
import {FixedUiElement} from "../Base/FixedUiElement";
import Translations from "../i18n/Translations";
@ -79,7 +79,7 @@ export default class PersonalLayersPanel extends UIElement {
])
const cb = new CheckBox(
const cb = new Toggle(
new SubtleButton(
icon,
content),

View file

@ -19,7 +19,6 @@ export default class ShareButton extends UIElement{
}
protected InnerUpdate(htmlElement: HTMLElement) {
super.InnerUpdate(htmlElement);
const self= this;
htmlElement.addEventListener('click', () => {
if (navigator.share) {

View file

@ -1,4 +1,3 @@
import {VerticalCombine} from "../Base/VerticalCombine";
import {UIElement} from "../UIElement";
import {VariableUiElement} from "../Base/VariableUIElement";
import {Translation} from "../i18n/Translation";
@ -9,7 +8,7 @@ import {SubtleButton} from "../Base/SubtleButton";
import {UIEventSource} from "../../Logic/UIEventSource";
import {Utils} from "../../Utils";
import State from "../../State";
import CheckBox from "../Input/CheckBox";
import Toggle from "../Input/Toggle";
import {FixedUiElement} from "../Base/FixedUiElement";
import Translations from "../i18n/Translations";
import Constants from "../../Models/Constants";
@ -40,7 +39,7 @@ export default class ShareScreen extends UIElement {
return Svg.no_checkmark_svg().SetStyle("width: 1.5em; display: inline-block;");
}
const includeLocation = new CheckBox(
const includeLocation = new Toggle(
new Combine([check(), tr.fsIncludeCurrentLocation]),
new Combine([nocheck(), tr.fsIncludeCurrentLocation]),
true
@ -75,7 +74,7 @@ export default class ShareScreen extends UIElement {
const currentBackground = new VariableUiElement(currentLayer.map(layer => {
return tr.fsIncludeCurrentBackgroundMap.Subs({name: layer?.name ?? ""}).Render();
}));
const includeCurrentBackground = new CheckBox(
const includeCurrentBackground = new Toggle(
new Combine([check(), currentBackground]),
new Combine([nocheck(), currentBackground]),
true
@ -90,7 +89,7 @@ export default class ShareScreen extends UIElement {
}, [currentLayer]));
const includeLayerChoices = new CheckBox(
const includeLayerChoices = new Toggle(
new Combine([check(), tr.fsIncludeCurrentLayers]),
new Combine([nocheck(), tr.fsIncludeCurrentLayers]),
true
@ -120,7 +119,7 @@ export default class ShareScreen extends UIElement {
for (const swtch of switches) {
const checkbox = new CheckBox(
const checkbox = new Toggle(
new Combine([check(), Translations.W(swtch.human)]),
new Combine([nocheck(), Translations.W(swtch.human)]), !swtch.reverse
);
@ -143,7 +142,7 @@ export default class ShareScreen extends UIElement {
}
this._options = new VerticalCombine(optionCheckboxes)
this._options = new Combine(optionCheckboxes).SetClass("flex flex-col")
const url = (currentLocation ?? new UIEventSource(undefined)).map(() => {
const host = window.location.host;
@ -216,8 +215,8 @@ export default class ShareScreen extends UIElement {
).onClick(async () => {
const shareData = {
title: Translations.W(layout.id)?.InnerRender() ?? "",
text: Translations.W(layout.description)?.InnerRender() ?? "",
title: Translations.W(layout.title)?.InnerRenderAsString() ?? "",
text: Translations.W(layout.description)?.InnerRenderAsString() ?? "",
url: self._link.data,
}
@ -251,11 +250,11 @@ export default class ShareScreen extends UIElement {
}
InnerRender(): string {
InnerRender(): UIElement {
const tr = Translations.t.general.sharescreen;
return new VerticalCombine([
return new Combine([
this._editLayout,
tr.intro,
this._link,
@ -264,7 +263,7 @@ export default class ShareScreen extends UIElement {
tr.embedIntro,
this._options,
this._iframeCode,
]).Render()
]).SetClass("flex flex-col")
}
}

View file

@ -7,6 +7,7 @@ import Translations from "../i18n/Translations";
import {VariableUiElement} from "../Base/VariableUIElement";
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
import {UIEventSource} from "../../Logic/UIEventSource";
import BaseUIElement from "../BaseUIElement";
export default class ThemeIntroductionPanel extends UIElement {
private languagePicker: UIElement;
@ -44,7 +45,7 @@ export default class ThemeIntroductionPanel extends UIElement {
this.SetClass("link-underline")
}
InnerRender(): string {
InnerRender(): BaseUIElement {
const layout : LayoutConfig = this._layout.data;
return new Combine([
layout.description,
@ -54,7 +55,7 @@ export default class ThemeIntroductionPanel extends UIElement {
"<br/>",
this.languagePicker,
...layout.CustomCodeSnippets()
]).Render()
])
}

View file

@ -64,10 +64,10 @@ export default class UserBadge extends UIElement {
}
InnerRender(): string {
InnerRender(): UIElement {
const user = this._userDetails.data;
if (!user.loggedIn) {
return this._loginButton.Render();
return this._loginButton;
}
const linkStyle = "flex items-baseline"
@ -138,7 +138,7 @@ export default class UserBadge extends UIElement {
return new Combine([
userIcon,
usertext,
]).Render()
])
}