@intuitionrobotics/thunderstorm
Version:
64 lines • 2.48 kB
JavaScript
/*
* Thunderstorm is a full web app framework!
*
* Typescript & Express backend infrastructure that natively runs on firebase function
* Typescript & React frontend infrastructure
*
* Copyright (C) 2020 Intuition Robotics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as React from 'react';
import { EntryComponentLoadingModule } from "./entry-component-loading-module.js";
import { BaseComponent } from "../../core/BaseComponent.js";
// noinspection TypeScriptPreferShortImport
import {} from '../../../shared/request-types.js';
export class ReactEntryComponentInjector extends BaseComponent {
myRef = React.createRef();
constructor(props) {
super(props);
this.state = { loading: false, progress: 0 };
}
__onRequestCompleted = (key, success) => {
if (key !== this.props.src)
return;
if (!success)
// Need to add error handling here...
return;
this.injectComponent(EntryComponentLoadingModule.getNode(key));
};
injectComponent(node) {
this.myRef.current?.appendChild(node);
this.setState({ loading: false });
}
componentDidMount() {
const src = this.props.src;
const node = EntryComponentLoadingModule.getNode(src);
if (node)
return this.injectComponent(node);
EntryComponentLoadingModule.loadScript(src, (progress) => this.setState({ progress }));
this.setState({ loading: true });
}
render() {
return React.createElement("div", { ref: this.myRef, id: this.props.src }, this.extracted());
}
extracted() {
const Loader = this.props.loader;
if (Loader)
return React.createElement(Loader, { progress: this.state.progress });
return React.createElement("div", { style: { width: "100%", height: "100%" } },
this.state.progress,
" %");
}
}
//# sourceMappingURL=ReactEntryComponentInjector.js.map