2019-02-04 09:31:52 -07:00
|
|
|
import {
|
|
|
|
createElement,
|
|
|
|
ComponentClass,
|
2020-02-28 09:35:32 -07:00
|
|
|
Attributes,
|
2019-02-04 09:31:52 -07:00
|
|
|
} from "react";
|
2018-01-20 07:46:44 -07:00
|
|
|
import { render } from "react-dom";
|
|
|
|
import { capitalize } from "lodash";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../i18next_wrapper";
|
2018-01-20 07:46:44 -07:00
|
|
|
|
|
|
|
/** Dynamically change the meta title of the page. */
|
|
|
|
export function updatePageInfo(pageName: string) {
|
|
|
|
if (pageName === "designer") { pageName = "Farm Designer"; }
|
2019-04-17 13:30:58 -06:00
|
|
|
document.title = `${t(capitalize(pageName))} - FarmBot`;
|
2018-01-20 07:46:44 -07:00
|
|
|
// Possibly add meta "content" here dynamically as well
|
|
|
|
}
|
|
|
|
|
2019-02-04 09:31:52 -07:00
|
|
|
export function attachToRoot<P>(type: ComponentClass<P>,
|
|
|
|
props?: Attributes & P) {
|
2018-01-20 07:46:44 -07:00
|
|
|
const node = document.createElement("DIV");
|
|
|
|
node.id = "root";
|
|
|
|
document.body.appendChild(node);
|
|
|
|
|
2019-02-04 09:31:52 -07:00
|
|
|
const reactElem = createElement(type, props);
|
2018-01-20 07:46:44 -07:00
|
|
|
const domElem = document.getElementById("root");
|
|
|
|
|
2018-08-15 08:50:21 -06:00
|
|
|
domElem && render(reactElem, domElem);
|
2018-01-20 07:46:44 -07:00
|
|
|
}
|