2020-07-20 19:08:13 +02:00
|
|
|
import * as React from "react";
|
|
|
|
import * as ReactDOM from "react-dom";
|
2020-08-09 18:58:19 +02:00
|
|
|
import {AbstractModal, ModalRenderer} from "tc-shared/ui/react-elements/ModalDefinitions";
|
2020-07-20 19:08:13 +02:00
|
|
|
|
|
|
|
const cssStyle = require("./PopoutRenderer.scss");
|
|
|
|
|
|
|
|
class TitleRenderer {
|
|
|
|
private readonly htmlContainer: HTMLElement;
|
|
|
|
private modalInstance: AbstractModal;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
const titleElements = document.getElementsByTagName("title");
|
|
|
|
if(titleElements.length === 0) {
|
|
|
|
this.htmlContainer = document.createElement("title");
|
|
|
|
document.head.appendChild(this.htmlContainer);
|
|
|
|
} else {
|
|
|
|
this.htmlContainer = titleElements[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setInstance(instance: AbstractModal) {
|
2020-09-24 15:51:22 +02:00
|
|
|
if(this.modalInstance) {
|
2020-07-20 19:08:13 +02:00
|
|
|
ReactDOM.unmountComponentAtNode(this.htmlContainer);
|
2020-09-24 15:51:22 +02:00
|
|
|
}
|
|
|
|
|
2020-07-20 19:08:13 +02:00
|
|
|
this.modalInstance = instance;
|
2020-09-24 15:51:22 +02:00
|
|
|
if(this.modalInstance) {
|
2021-01-17 23:11:21 +01:00
|
|
|
ReactDOM.render(<>{this.modalInstance.renderTitle()}</>, this.htmlContainer);
|
2020-09-24 15:51:22 +02:00
|
|
|
}
|
2020-07-20 19:08:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BodyRenderer {
|
|
|
|
private readonly htmlContainer: HTMLElement;
|
|
|
|
private modalInstance: AbstractModal;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.htmlContainer = document.createElement("div");
|
|
|
|
this.htmlContainer.classList.add(cssStyle.container);
|
|
|
|
|
|
|
|
document.body.appendChild(this.htmlContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
setInstance(instance: AbstractModal) {
|
2021-01-09 14:25:11 +01:00
|
|
|
if(this.modalInstance) {
|
2020-07-20 19:08:13 +02:00
|
|
|
ReactDOM.unmountComponentAtNode(this.htmlContainer);
|
2021-01-09 14:25:11 +01:00
|
|
|
}
|
|
|
|
|
2020-07-20 19:08:13 +02:00
|
|
|
this.modalInstance = instance;
|
2021-01-09 14:25:11 +01:00
|
|
|
if(this.modalInstance) {
|
2020-07-20 19:08:13 +02:00
|
|
|
ReactDOM.render(<>{this.modalInstance.renderBody()}</>, this.htmlContainer);
|
2021-01-09 14:25:11 +01:00
|
|
|
}
|
2020-07-20 19:08:13 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-09 18:58:19 +02:00
|
|
|
|
|
|
|
export class WebModalRenderer implements ModalRenderer {
|
|
|
|
private readonly titleRenderer: TitleRenderer;
|
|
|
|
private readonly bodyRenderer: BodyRenderer;
|
|
|
|
|
|
|
|
private currentModal: AbstractModal;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.titleRenderer = new TitleRenderer();
|
|
|
|
this.bodyRenderer = new BodyRenderer();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderModal(modal: AbstractModal | undefined) {
|
2021-01-22 16:50:55 +01:00
|
|
|
if(this.currentModal === modal) {
|
2020-08-09 18:58:19 +02:00
|
|
|
return;
|
2021-01-22 16:50:55 +01:00
|
|
|
}
|
2020-08-09 18:58:19 +02:00
|
|
|
|
|
|
|
this.currentModal = modal;
|
|
|
|
this.titleRenderer.setInstance(modal);
|
|
|
|
this.bodyRenderer.setInstance(modal);
|
|
|
|
}
|
|
|
|
}
|