mapcomplete/UI/FullScreenMessageBoxHandler.ts

65 lines
1.8 KiB
TypeScript
Raw Normal View History

import {UIElement} from "./UIElement";
import Translations from "./i18n/Translations";
import {State} from "../State";
import Combine from "./Base/Combine";
/**
* Handles the full screen popup on mobile
*/
export class FullScreenMessageBox extends UIElement {
private _uielement: UIElement;
private returnToTheMap: UIElement;
constructor(onClear: (() => void)) {
super(undefined);
const self = this;
State.state.fullScreenMessage.addCallback(uielement => {
return self._uielement = uielement?.SetClass("messagesboxmobile-scroll")?.Activate();
});
this._uielement = State.state.fullScreenMessage.data;
this.ListenTo(State.state.fullScreenMessage);
this.HideOnEmpty(true);
State.state.fullScreenMessage.addCallback(latestData => {
if (latestData === undefined) {
location.hash = "";
} else {
location.hash = "#element";
}
this.Update();
})
2020-07-25 18:00:08 +02:00
if (window !== undefined) {
window.onhashchange = function () {
if (location.hash === "") {
// No more element: back to the map!
2020-09-05 01:40:43 +02:00
self._uielement?.setData(undefined);
2020-07-25 18:00:08 +02:00
onClear();
}
2020-06-29 03:12:44 +02:00
}
}
this.returnToTheMap = Translations.t.general.returnToTheMap.Clone()
.SetClass("to-the-map")
2020-07-21 00:07:04 +02:00
.onClick(() => {
console.log("Returning...")
State.state.fullScreenMessage.setData(undefined);
2020-07-21 00:07:04 +02:00
onClear();
self.Update();
});
2020-06-29 03:12:44 +02:00
}
2020-06-29 03:12:44 +02:00
InnerRender(): string {
if (this._uielement === undefined) {
return "";
}
2020-09-05 01:40:43 +02:00
return new Combine([this._uielement, this.returnToTheMap]).Render();
}
}