wisemapping-frontend/packages/webapp/src/app.tsx

106 lines
4.4 KiB
TypeScript
Raw Normal View History

import React, { ReactElement } from 'react';
import { IntlProvider } from 'react-intl';
import { Route, Switch, Redirect, BrowserRouter as Router } from 'react-router-dom';
import RegistrationSuccessPage from './components/registration-success-page';
import ForgotPasswordSuccessPage from './components/forgot-password-success-page';
import RegistationPage from './components/registration-page';
import LoginPage from './components/login-page';
import store from './redux/store';
import { ForgotPasswordPage } from './components/forgot-password-page';
import { Provider } from 'react-redux';
import { QueryClient, QueryClientProvider } from 'react-query';
import { theme } from './theme';
import AppI18n, { Locales } from './classes/app-i18n';
import MapsPage from './components/maps-page';
2022-02-06 01:42:43 +01:00
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider, Theme, StyledEngineProvider } from '@mui/material/styles';
2021-02-27 21:15:48 +01:00
import GoogleAnalytics from 'react-ga';
2022-02-06 00:09:43 +01:00
import EditorPage from './components/editor-page';
2021-02-27 21:15:48 +01:00
2022-02-06 01:42:43 +01:00
declare module '@mui/styles/defaultTheme' {
2022-02-06 20:12:20 +01:00
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface DefaultTheme extends Theme { }
2022-02-06 01:42:43 +01:00
}
2021-02-27 21:15:48 +01:00
// Google Analytics Initialization.
2022-02-12 07:27:07 +01:00
GoogleAnalytics.initialize('UA-2347723-1');
2022-02-12 09:13:24 +01:00
GoogleAnalytics.pageview(window.location.pathname + window.location.search);
2021-02-02 09:20:35 +01:00
const queryClient = new QueryClient({
2021-02-23 07:37:29 +01:00
defaultOptions: {
queries: {
refetchIntervalInBackground: false,
staleTime: 5 * 1000 * 60, // 10 minutes
},
},
});
2021-02-02 09:20:35 +01:00
2021-02-23 07:37:29 +01:00
const App = (): ReactElement => {
2022-02-10 01:36:31 +01:00
const locale = AppI18n.getBrowserLocale();
2022-01-25 19:10:40 +01:00
// global variables set server-side
2022-02-06 20:12:20 +01:00
const istTryMode = global.memoryPersistence;
2022-01-25 19:10:40 +01:00
const mapId = parseInt(global.mapId, 10);
2021-02-23 07:37:29 +01:00
return locale.message ? (
<Provider store={store}>
<QueryClientProvider client={queryClient}>
<IntlProvider
locale={locale.code}
defaultLocale={Locales.EN.code}
messages={locale.message as Record<string, string>}
>
2022-02-06 01:42:43 +01:00
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<CssBaseline />
<Router>
<Switch>
<Route exact path="/">
<Redirect to="/c/login" />
</Route>
<Route path="/c/login"
component={LoginPage}
/>
<Route
path="/c/registration"
component={RegistationPage}
/>
<Route
path="/c/registration-success"
component={RegistrationSuccessPage}
/>
<Route
path="/c/forgot-password"
component={ForgotPasswordPage}
/>
<Route
path="/c/forgot-password-success"
component={ForgotPasswordSuccessPage}
/>
<Route
exact path="/c/maps/"
component={MapsPage}
/>
<Route exact path="/c/maps/:id/edit">
2022-02-06 20:12:20 +01:00
<EditorPage isTryMode={istTryMode} mapId={mapId} />
2022-02-06 01:42:43 +01:00
</Route>
<Route exact path="/c/maps/:id/try">
2022-02-06 20:12:20 +01:00
<EditorPage isTryMode={istTryMode} mapId={mapId} />
2022-02-06 01:42:43 +01:00
</Route>
</Switch>
</Router>
</ThemeProvider>
</StyledEngineProvider>
2021-02-23 07:37:29 +01:00
</IntlProvider>
</QueryClientProvider>
</Provider>
) : (
<div>Loading ... </div>
);
};
export default App;