Farmbot-Web-App/frontend/util/page.ts

28 lines
806 B
TypeScript
Raw Permalink Normal View History

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";
import { render } from "react-dom";
import { capitalize } from "lodash";
2019-04-02 13:59:37 -06:00
import { t } from "../i18next_wrapper";
/** 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`;
// 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) {
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);
const domElem = document.getElementById("root");
domElem && render(reactElem, domElem);
}