import React, { Suspense } from "react";
import history from "utils/history";
import AppHeader from "pages/common/AppHeader";
import { Redirect, Route, Router, Switch } from "react-router-dom";
import {
APP_VIEW_URL,
APPLICATIONS_URL,
AUTH_LOGIN_URL,
BASE_LOGIN_URL,
BASE_SIGNUP_URL,
BASE_URL,
BUILDER_URL,
getApplicationViewerPageURL,
ORG_URL,
PAGE_NOT_FOUND_URL,
SERVER_ERROR_URL,
SIGN_UP_URL,
USER_AUTH_URL,
USERS_URL,
} from "constants/routes";
import OrganizationLoader from "pages/organization/loader";
import ApplicationListLoader from "pages/Applications/loader";
import EditorLoader from "pages/Editor/loader";
import AppViewerLoader from "pages/AppViewer/loader";
import LandingScreen from "./LandingScreen";
import UserAuth from "pages/UserAuth";
import Users from "pages/users";
import PageNotFound from "pages/common/PageNotFound";
import PageLoadingBar from "pages/common/PageLoadingBar";
import ServerUnavailable from "pages/common/ServerUnavailable";
import { getThemeDetails } from "selectors/themeSelectors";
import { ThemeMode } from "reducers/uiReducers/themeReducer";
import { AppState } from "reducers";
import { setThemeMode } from "actions/themeActions";
import { connect } from "react-redux";
import * as Sentry from "@sentry/react";
import AnalyticsUtil from "utils/AnalyticsUtil";
import { trimTrailingSlash } from "utils/helpers";
const SentryRoute = Sentry.withSentryRouting(Route);
const loadingIndicator = ;
function changeAppBackground(currentTheme: any) {
if (
trimTrailingSlash(window.location.pathname) === "/applications" ||
window.location.pathname.indexOf("/settings/") !== -1
) {
document.body.style.backgroundColor =
currentTheme.colors.homepageBackground;
} else {
document.body.style.backgroundColor = currentTheme.colors.appBackground;
}
}
class AppRouter extends React.Component {
unlisten: any;
componentDidMount() {
// This is needed for the route switch.
AnalyticsUtil.logEvent("ROUTE_CHANGE", { path: window.location.pathname });
this.unlisten = history.listen((location: any) => {
AnalyticsUtil.logEvent("ROUTE_CHANGE", { path: location.pathname });
changeAppBackground(this.props.currentTheme);
});
}
componentWillUnmount() {
this.unlisten();
}
render() {
const { currentTheme } = this.props;
// This is needed for the theme switch.
changeAppBackground(currentTheme);
return (
);
}
}
const mapStateToProps = (state: AppState) => ({
currentTheme: getThemeDetails(state).theme,
});
const mapDispatchToProps = (dispatch: any) => ({
setTheme: (mode: ThemeMode) => {
dispatch(setThemeMode(mode));
},
});
export default connect(mapStateToProps, mapDispatchToProps)(AppRouter);