import "./app-init.scss" import React from "react" import { render } from "react-dom"; import { t } from "@lingui/macro"; import { CubeSpinner } from "../spinner"; import { apiBase } from "../../api"; import { _i18n } from "../../i18n"; interface Props { serviceWaitingList?: string[]; } export class AppInit extends React.Component { static async start(rootElem: HTMLElement) { render(, rootElem); // show loading indicator asap await AppInit.readyStateCheck(rootElem); // wait while all good to run } protected static async readyStateCheck(rootElem: HTMLElement) { const waitingList = await apiBase.get("/ready"); if (waitingList.length > 0) { // update waiting state render(, rootElem); // check again in 1-5 seconds return new Promise(resolve => { const timeoutDelay = 1000 + Math.random() * 4000; setTimeout(() => resolve(AppInit.readyStateCheck(rootElem)), timeoutDelay); }); } } render() { const { serviceWaitingList = [] } = this.props; const serviceNames = serviceWaitingList.join(", "); return (
Lens - {_i18n._(t`Loading`)}..
{serviceWaitingList.length > 0 && (

{_i18n._(t`Waiting services to be running`)}: {serviceNames}

)}
) } }