bazarr/frontend/src/App/index.tsx

61 lines
1.7 KiB
TypeScript
Raw Normal View History

import { LoadingIndicator } from "@/components";
import ErrorBoundary from "@/components/ErrorBoundary";
import { useNotification } from "@/modules/redux/hooks";
import { useReduxStore } from "@/modules/redux/hooks/base";
import SocketIO from "@/modules/socketio";
import LaunchError from "@/pages/LaunchError";
import Sidebar from "@/Sidebar";
import { Environment } from "@/utilities";
import { FunctionComponent, useEffect } from "react";
2021-04-23 16:18:09 +00:00
import { Row } from "react-bootstrap";
import { Navigate, Outlet } from "react-router-dom";
import { useEffectOnceWhen } from "rooks";
2021-03-25 14:22:43 +00:00
import Header from "./Header";
const App: FunctionComponent = () => {
const { status } = useReduxStore((s) => s.site);
2021-03-25 14:22:43 +00:00
useEffect(() => {
SocketIO.initialize();
}, []);
2021-03-25 14:22:43 +00:00
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
}
}, status === "initialized");
2021-03-25 14:22:43 +00:00
if (status === "unauthenticated") {
return <Navigate to="/login"></Navigate>;
} else if (status === "uninitialized") {
2021-03-25 14:22:43 +00:00
return (
<LoadingIndicator>
<span>Please wait</span>
</LoadingIndicator>
);
} else if (status === "error") {
return <LaunchError>Cannot Initialize Bazarr</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>
<Outlet></Outlet>
2021-08-31 16:08:47 +00:00
</Row>
2021-08-16 16:46:10 +00:00
</ErrorBoundary>
);
2021-03-25 14:22:43 +00:00
};
export default App;