mapcomplete/UI/CenterMessageBox.ts

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

44 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-09-08 21:40:48 +02:00
import Translations from "./i18n/Translations"
import { VariableUiElement } from "./Base/VariableUIElement"
import FeaturePipelineState from "../Logic/State/FeaturePipelineState"
import Loading from "./Base/Loading"
2020-06-24 00:35:19 +02:00
2021-06-12 02:58:32 +02:00
export default class CenterMessageBox extends VariableUiElement {
constructor(state: FeaturePipelineState) {
2022-09-08 21:40:48 +02:00
const updater = state.featurePipeline
const t = Translations.t.centerMessage
2021-06-12 02:58:32 +02:00
const message = updater.runningQuery.map(
2022-09-08 21:40:48 +02:00
(isRunning) => {
2021-06-12 02:58:32 +02:00
if (isRunning) {
2022-09-08 21:40:48 +02:00
return { el: new Loading(t.loadingData) }
2021-06-12 02:58:32 +02:00
}
if (!updater.sufficientlyZoomed.data) {
2022-09-08 21:40:48 +02:00
return { el: t.zoomIn }
2021-06-12 02:58:32 +02:00
}
if (updater.timeout.data > 0) {
2022-09-08 21:40:48 +02:00
return { el: t.retrying.Subs({ count: "" + updater.timeout.data }) }
2021-06-12 02:58:32 +02:00
}
2022-09-08 21:40:48 +02:00
return { el: t.ready, isDone: true }
2021-06-12 02:58:32 +02:00
},
[updater.timeout, updater.sufficientlyZoomed, state.locationControl]
)
2022-09-08 21:40:48 +02:00
super(message.map((toShow) => toShow.el))
2022-09-08 21:40:48 +02:00
this.SetClass(
"flex justify-center " +
"rounded-3xl bg-white text-xl font-bold pointer-events-none p-4"
)
2021-06-12 02:58:32 +02:00
this.SetStyle("transition: opacity 750ms linear")
2022-09-08 21:40:48 +02:00
message.addCallbackAndRun((toShow) => {
const isDone = toShow.isDone ?? false
2021-06-12 02:58:32 +02:00
if (isDone) {
this.SetStyle("transition: opacity 750ms linear; opacity: 0")
} else {
this.SetStyle("transition: opacity 750ms linear; opacity: 0.75")
}
})
2020-06-24 00:35:19 +02:00
}
}