bazarr/frontend/src/App/index.tsx

99 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-08-31 16:08:47 +00:00
import React, { FunctionComponent, useEffect } from "react";
2021-04-23 16:18:09 +00:00
import { Row } from "react-bootstrap";
import { Provider } from "react-redux";
import { Route, Switch } from "react-router";
import { BrowserRouter, Redirect } from "react-router-dom";
import { useEffectOnceWhen } from "rooks";
import Socketio from "../@modules/socketio";
import { useReduxStore } from "../@redux/hooks/base";
2021-03-25 14:22:43 +00:00
import { useNotification } from "../@redux/hooks/site";
import store from "../@redux/store";
2021-03-25 14:22:43 +00:00
import { LoadingIndicator, ModalProvider } from "../components";
2021-08-31 16:08:47 +00:00
import Router from "../Router";
2021-03-25 14:22:43 +00:00
import Sidebar from "../Sidebar";
import Auth from "../special-pages/AuthPage";
2021-08-16 16:46:10 +00:00
import ErrorBoundary from "../special-pages/ErrorBoundary";
2021-04-23 16:18:09 +00:00
import LaunchError from "../special-pages/LaunchError";
import { Environment } from "../utilities";
2021-03-25 14:22:43 +00:00
import Header from "./Header";
// Sidebar Toggle
interface Props {}
const App: FunctionComponent<Props> = () => {
const { initialized, auth } = useReduxStore((s) => s.site);
2021-05-09 03:22:24 +00:00
const notify = useNotification("has-update", 10 * 1000);
2021-03-25 14:22:43 +00:00
// Has any update?
useEffectOnceWhen(() => {
if (Environment.hasUpdate) {
notify({
type: "info",
message: "A new version of Bazarr is ready, restart is required",
// TODO: Restart action
});
2021-03-25 14:22:43 +00:00
}
}, initialized === true);
2021-03-25 14:22:43 +00:00
if (!auth) {
return <Redirect to="/login"></Redirect>;
}
if (typeof initialized === "boolean" && initialized === false) {
return (
<LoadingIndicator>
<span>Please wait</span>
</LoadingIndicator>
);
} else if (typeof initialized === "string") {
2021-04-23 16:18:09 +00:00
return <LaunchError>{initialized}</LaunchError>;
2021-03-25 14:22:43 +00:00
}
2021-08-16 16:46:10 +00:00
return (
<ErrorBoundary>
2021-08-31 16:08:47 +00:00
<Row noGutters className="header-container">
<Header></Header>
</Row>
<Row noGutters className="flex-nowrap">
<Sidebar></Sidebar>
<ModalProvider>
<Router></Router>
</ModalProvider>
</Row>
2021-08-16 16:46:10 +00:00
</ErrorBoundary>
);
2021-03-25 14:22:43 +00:00
};
const MainRouter: FunctionComponent = () => {
useEffect(() => {
Socketio.initialize();
}, []);
return (
<BrowserRouter basename={Environment.baseUrl}>
<Switch>
<Route exact path="/login">
<Auth></Auth>
</Route>
<Route path="/">
<App></App>
</Route>
</Switch>
</BrowserRouter>
);
};
const Main: FunctionComponent = () => {
return (
<Provider store={store}>
{/* TODO: Enabled Strict Mode after react-bootstrap upgrade to bootstrap 5 */}
{/* <React.StrictMode> */}
<MainRouter></MainRouter>
{/* </React.StrictMode> */}
</Provider>
);
};
export default Main;