mapcomplete/UI/Popup/FeatureInfoBox.ts

81 lines
2.8 KiB
TypeScript
Raw Normal View History

2020-10-14 10:15:09 +00:00
import {UIElement} from "../UIElement";
import {UIEventSource} from "../../Logic/UIEventSource";
2020-10-27 00:01:34 +00:00
import LayerConfig from "../../Customizations/JSON/LayerConfig";
import EditableTagRendering from "./EditableTagRendering";
import QuestionBox from "./QuestionBox";
import Combine from "../Base/Combine";
import TagRenderingAnswer from "./TagRenderingAnswer";
import State from "../../State";
2021-01-07 03:50:12 +00:00
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
2021-01-08 01:13:44 +00:00
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
2021-01-25 03:21:22 +00:00
export default class FeatureInfoBox extends UIElement {
private _component: ScrollableFullScreen;
constructor(
2020-10-27 00:01:34 +00:00
tags: UIEventSource<any>,
2021-01-21 23:40:15 +00:00
layerConfig: LayerConfig,
2021-01-25 02:12:09 +00:00
onClose: () => void
) {
2021-01-25 03:21:22 +00:00
super();
2020-11-17 15:29:51 +00:00
if (layerConfig === undefined) {
2020-11-02 17:59:21 +00:00
throw "Undefined layerconfig"
}
2021-01-25 03:21:22 +00:00
const title = FeatureInfoBox.GenerateTitleBar(tags, layerConfig);
const contents = FeatureInfoBox.GenerateContent(tags, layerConfig);
this._component = new ScrollableFullScreen(title, contents, onClose)
2021-01-25 02:12:09 +00:00
}
2021-01-25 03:21:22 +00:00
InnerRender(): string {
return this._component.Render();
}
private static GenerateTitleBar(tags: UIEventSource<any>,
layerConfig: LayerConfig): UIElement {
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI", undefined))
2021-01-25 02:12:09 +00:00
.SetClass("text-2xl break-words font-bold p-2");
2021-01-08 01:13:44 +00:00
const titleIcons = new Combine(
2021-01-21 22:39:31 +00:00
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon)
2021-01-25 02:12:09 +00:00
.SetClass("block w-8 h-8 align-baseline box-content p-0.5")))
.SetClass("flex flex-row flex-wrap pt-1 items-center mr-2");
2021-01-25 03:21:22 +00:00
return new Combine([
2021-01-25 02:12:09 +00:00
new Combine([title, titleIcons]).SetClass("flex flex-grow justify-between")
])
}
2021-01-25 03:21:22 +00:00
private static GenerateContent(tags: UIEventSource<any>,
layerConfig: LayerConfig): UIElement {
2021-01-25 02:12:09 +00:00
let questionBox: UIElement = undefined;
if (State.state.featureSwitchUserbadge.data) {
2020-12-08 22:44:34 +00:00
questionBox = new QuestionBox(tags, layerConfig.tagRenderings);
}
2020-12-08 22:44:34 +00:00
let questionBoxIsUsed = false;
2021-01-08 01:13:44 +00:00
const renderings = layerConfig.tagRenderings.map(tr => {
if (tr.question === null) {
2020-12-08 22:44:34 +00:00
questionBoxIsUsed = true;
// This is the question box!
return questionBox;
}
return new EditableTagRendering(tags, tr);
});
if (!questionBoxIsUsed) {
2021-01-08 01:13:44 +00:00
renderings.push(questionBox);
}
2021-01-08 15:49:42 +00:00
const tail = new Combine([]).SetClass("only-on-mobile");
2021-01-08 01:13:44 +00:00
2021-01-25 02:12:09 +00:00
return new Combine([
2021-01-08 01:13:44 +00:00
...renderings,
tail.SetClass("featureinfobox-tail")
]
2021-01-27 01:26:57 +00:00
).SetClass("block")
}
2020-07-20 13:54:50 +00:00
2021-01-25 03:21:22 +00:00
}