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 16:00:08 +00:00
if (window !== undefined) {
window.onhashchange = function () {
if (location.hash === "") {
// No more element: back to the map!
2020-09-04 23:40:43 +00:00
self._uielement?.setData(undefined);
2020-07-25 16:00:08 +00:00
onClear();
}
2020-06-29 01:12:44 +00:00
}
}
this.returnToTheMap = Translations.t.general.returnToTheMap.Clone()
.SetClass("to-the-map")
2020-07-20 22:07:04 +00:00
.onClick(() => {
console.log("Returning...")
State.state.fullScreenMessage.setData(undefined);
2020-07-20 22:07:04 +00:00
onClear();
self.Update();
});
2020-06-29 01:12:44 +00:00
}
2020-06-29 01:12:44 +00:00
InnerRender(): string {
if (this._uielement === undefined) {
return "";
}
2020-09-04 23:40:43 +00:00
return new Combine([this._uielement, this.returnToTheMap]).Render();
}
}