mapcomplete/UI/Popup/FeatureInfoBox.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.8 KiB
TypeScript
Raw Normal View History

import { Store, UIEventSource } from "../../Logic/UIEventSource"
2020-10-27 01:01:34 +01:00
import QuestionBox from "./QuestionBox"
import Combine from "../Base/Combine"
import TagRenderingAnswer from "./TagRenderingAnswer"
2021-01-08 02:13:44 +01:00
import ScrollableFullScreen from "../Base/ScrollableFullScreen"
import Constants from "../../Models/Constants"
import SharedTagRenderings from "../../Customizations/SharedTagRenderings"
2021-06-14 02:39:23 +02:00
import BaseUIElement from "../BaseUIElement"
2022-11-08 14:37:48 +01:00
import { VariableUiElement } from "../Base/VariableUIElement"
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
import Toggle from "../Input/Toggle"
import Lazy from "../Base/Lazy"
2022-05-01 04:17:40 +02:00
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState"
2022-11-08 14:37:48 +01:00
import Svg from "../../Svg"
import Translations from "../i18n/Translations"
export default class FeatureInfoBox extends ScrollableFullScreen {
2021-06-14 02:39:23 +02:00
public constructor(
2020-10-27 01:01:34 +01:00
tags: UIEventSource<any>,
layerConfig: LayerConfig,
2022-05-01 04:17:40 +02:00
state: FeaturePipelineState,
2022-07-08 03:14:55 +02:00
options?: {
hashToShow?: string
isShown?: UIEventSource<boolean>
setHash?: true | boolean
}
) {
const showAllQuestions = state.featureSwitchShowAllQuestions.map(
(fsShow) => fsShow || state.showAllQuestionsAtOnce.data,
[state.showAllQuestionsAtOnce]
)
super(
2023-04-14 04:34:13 +02:00
() => undefined,
() => FeatureInfoBox.GenerateContent(tags, layerConfig, state, showAllQuestions),
2022-07-08 03:14:55 +02:00
options?.hashToShow ?? tags.data.id ?? "item",
options?.isShown,
options
2022-09-08 21:40:48 +02:00
)
2020-11-17 16:29:51 +01:00
if (layerConfig === undefined) {
throw "Undefined layerconfig"
2020-11-02 18:59:21 +01:00
}
2021-01-25 03:12:09 +01:00
}
2022-07-13 17:58:01 +02:00
public static GenerateContent(
tags: UIEventSource<any>,
layerConfig: LayerConfig
2022-12-16 13:45:07 +01:00
): BaseUIElement {
return new Toggle(
2022-12-16 13:45:07 +01:00
new Combine([
Svg.delete_icon_svg().SetClass("w-8 h-8"),
Translations.t.delete.isDeleted,
]).SetClass("flex justify-center font-bold items-center"),
FeatureInfoBox.GenerateMainContent(tags, layerConfig),
2022-12-16 13:45:07 +01:00
tags.map((t) => t["_deleted"] == "yes")
)
}
private static GenerateMainContent(
2022-07-13 17:58:01 +02:00
tags: UIEventSource<any>,
layerConfig: LayerConfig
2022-05-01 04:17:40 +02:00
): BaseUIElement {
const t = Translations.t.general
2022-11-08 14:37:48 +01:00
const withQuestion = layerConfig.tagRenderings.filter(
(tr) => tr.question !== undefined
).length
const allRenderings: BaseUIElement[] = [
new VariableUiElement(
2022-11-08 14:37:48 +01:00
tags
.map((data) => data["_newly_created"])
2022-11-08 14:37:48 +01:00
.map((isCreated) => {
if (isCreated === undefined) {
2022-11-08 14:37:48 +01:00
return undefined
}
const createdDate = new Date(isCreated)
const secondsSinceCreation = (Date.now() - createdDate.getTime()) / 1000
if (secondsSinceCreation >= 60 * 5) {
return undefined
}
2022-11-08 14:37:48 +01:00
const els = []
const thanks = new Combine([
Svg.party_svg().SetClass(
"w-12 h-12 shrink-0 p-1 m-1 bg-white rounded-full block"
),
t.newlyCreated,
]).SetClass("flex w-full thanks content-center")
2022-11-08 14:37:48 +01:00
els.push(thanks)
if (withQuestion > 0) {
els.push(t.feelFreeToSkip)
}
2022-11-08 14:37:48 +01:00
return new Combine(els).SetClass("pb-4 mb-4 border-b block border-black")
})
),
]
return new Combine(allRenderings).SetClass("block")
}
}