2023-03-08 01:36:27 +01:00
|
|
|
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"
|
2021-04-21 01:26:36 +02:00
|
|
|
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"
|
2021-08-07 23:11:34 +02:00
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
2021-11-10 18:42:31 +01:00
|
|
|
import Toggle from "../Input/Toggle"
|
2022-01-19 20:34:04 +01:00
|
|
|
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"
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2021-02-25 02:23:26 +01:00
|
|
|
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>,
|
2021-06-22 03:16:45 +02:00
|
|
|
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
|
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
) {
|
2023-03-08 01:36:27 +01:00
|
|
|
const showAllQuestions = state.featureSwitchShowAllQuestions.map(
|
|
|
|
(fsShow) => fsShow || state.showAllQuestionsAtOnce.data,
|
|
|
|
[state.showAllQuestionsAtOnce]
|
|
|
|
)
|
2022-01-19 20:34:04 +01:00
|
|
|
super(
|
2023-04-14 04:34:13 +02:00
|
|
|
() => undefined,
|
2023-03-08 01:36:27 +01:00
|
|
|
() => 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
|
|
|
)
|
2021-04-17 23:36:46 +02:00
|
|
|
|
2020-11-17 16:29:51 +01:00
|
|
|
if (layerConfig === undefined) {
|
2021-02-25 02:23:26 +01:00
|
|
|
throw "Undefined layerconfig"
|
2020-11-02 18:59:21 +01:00
|
|
|
}
|
2021-01-25 03:12:09 +01:00
|
|
|
}
|
2021-02-20 02:25:29 +01:00
|
|
|
|
2022-07-13 17:58:01 +02:00
|
|
|
public static GenerateContent(
|
2022-12-16 01:09:18 +01:00
|
|
|
tags: UIEventSource<any>,
|
2023-04-15 03:15:17 +02:00
|
|
|
layerConfig: LayerConfig
|
2022-12-16 13:45:07 +01:00
|
|
|
): BaseUIElement {
|
2022-12-16 01:09:18 +01:00
|
|
|
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"),
|
2023-04-15 03:15:17 +02:00
|
|
|
FeatureInfoBox.GenerateMainContent(tags, layerConfig),
|
2022-12-16 13:45:07 +01:00
|
|
|
tags.map((t) => t["_deleted"] == "yes")
|
2022-12-16 01:09:18 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
private static GenerateMainContent(
|
2022-07-13 17:58:01 +02:00
|
|
|
tags: UIEventSource<any>,
|
2023-04-15 03:15:17 +02:00
|
|
|
layerConfig: LayerConfig
|
2022-05-01 04:17:40 +02:00
|
|
|
): BaseUIElement {
|
2022-11-07 23:12:31 +01:00
|
|
|
const t = Translations.t.general
|
2021-01-04 04:06:21 +01:00
|
|
|
|
2022-11-08 14:37:48 +01:00
|
|
|
const withQuestion = layerConfig.tagRenderings.filter(
|
|
|
|
(tr) => tr.question !== undefined
|
|
|
|
).length
|
2022-11-07 23:12:31 +01:00
|
|
|
|
|
|
|
const allRenderings: BaseUIElement[] = [
|
|
|
|
new VariableUiElement(
|
2022-11-08 14:37:48 +01:00
|
|
|
tags
|
2023-04-06 01:33:08 +02:00
|
|
|
.map((data) => data["_newly_created"])
|
2022-11-08 14:37:48 +01:00
|
|
|
.map((isCreated) => {
|
2023-01-09 20:56:39 +01:00
|
|
|
if (isCreated === undefined) {
|
2022-11-08 14:37:48 +01:00
|
|
|
return undefined
|
|
|
|
}
|
2023-01-09 20:56:39 +01:00
|
|
|
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,
|
2022-11-07 23:12:31 +01:00
|
|
|
]).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-07 23:12:31 +01:00
|
|
|
|
2022-11-08 14:37:48 +01:00
|
|
|
return new Combine(els).SetClass("pb-4 mb-4 border-b block border-black")
|
|
|
|
})
|
|
|
|
),
|
2022-11-07 23:12:31 +01:00
|
|
|
]
|
2021-10-23 00:31:41 +02:00
|
|
|
|
2022-01-19 20:34:04 +01:00
|
|
|
return new Combine(allRenderings).SetClass("block")
|
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|