@intuitionrobotics/thunderstorm
Version:
88 lines • 3.61 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 { renderApp } from "./AppWrapper.js";
import { BeLogged, LogClient_Browser, Module } from "@intuitionrobotics/ts-common";
import { XhrHttpModule } from "../modules/http/XhrHttpModule.js";
import { ToastModule } from "../modules/toaster/ToasterModule.js";
import { RoutingModule } from "../modules/routing/RoutingModule.js";
import { BrowserHistoryModule } from "../modules/HistoryModule.js";
import { StorageModule } from "../modules/StorageModule.js";
import { ResourcesModule } from "../modules/ResourcesModule.js";
import {} from "../../shared/request-types.js";
import { AbstractThunder, dispatch_requestCompleted } from "./AbstractThunder.js";
import { ThunderstormModule } from "../modules/ThunderstormModule.js";
import { DialogModule } from "../modules/dialog/DialogModule.js";
import { BaseHttpRequest } from "../../shared/BaseHttpRequest.js";
import { ThunderDispatcher } from "./thunder-dispatcher.js";
export const ErrorHandler_Toast = (request, resError) => {
const errorMessage = request.errorMessage || resError?.debugMessage;
return errorMessage && ToastModule.toastError(errorMessage);
};
export const SuccessHandler_Toast = (request) => request.successMessage && ToastModule.toastSuccess(request.successMessage);
export const ErrorHandler_Dispatch = (request) => dispatch_requestCompleted.dispatchUI(request.key, false, request.requestData);
export const SuccessHandler_Dispatch = (request) => dispatch_requestCompleted.dispatchUI(request.key, true, request.requestData);
const modules = [
ThunderstormModule,
XhrHttpModule,
RoutingModule,
BrowserHistoryModule,
ToastModule,
DialogModule,
StorageModule,
ResourcesModule
];
export class Thunder extends AbstractThunder {
mainApp;
constructor() {
super();
this.addModules(...modules);
}
static getInstance() {
return Thunder.instance;
}
init() {
BeLogged.addClient(LogClient_Browser);
super.init();
XhrHttpModule.setErrorHandlers([ErrorHandler_Toast, ErrorHandler_Dispatch]);
XhrHttpModule.setSuccessHandlers([SuccessHandler_Toast, SuccessHandler_Dispatch]);
XhrHttpModule.addDefaultResponseHandler((request) => {
if (request.getStatus() !== 401)
return false;
const unauthenticatedDispatcher = new ThunderDispatcher("onUnauthenticatedResponse");
unauthenticatedDispatcher.dispatchUI();
unauthenticatedDispatcher.dispatchModule();
return true;
});
return this;
}
renderApp = () => {
renderApp();
};
setMainApp(mainApp) {
this.mainApp = mainApp;
return this;
}
getMainApp() {
return this.mainApp;
}
}
//# sourceMappingURL=Thunder.js.map