lemmy-ui/src/shared/components/app/app.tsx

64 lines
2 KiB
TypeScript
Raw Normal View History

2021-02-22 02:39:04 +00:00
import { Component } from "inferno";
import { Provider } from "inferno-i18next-dess";
import { Route, Switch } from "inferno-router";
2023-05-14 23:49:55 +00:00
import { IsoDataOptionalSite } from "shared/interfaces";
import { i18n } from "../../i18next";
import { routes } from "../../routes";
2023-05-14 15:08:06 +00:00
import { isAuthPath, setIsoData } from "../../utils";
import AuthGuard from "../common/auth-guard";
import ErrorGuard from "../common/error-guard";
import { ErrorPage } from "./error-page";
2021-02-22 02:39:04 +00:00
import { Footer } from "./footer";
import { Navbar } from "./navbar";
2021-02-22 02:39:04 +00:00
import "./styles.scss";
import { Theme } from "./theme";
export class App extends Component<any, any> {
2023-05-14 23:49:55 +00:00
private isoData: IsoDataOptionalSite = setIsoData(this.context);
constructor(props: any, context: any) {
super(props, context);
}
render() {
2023-05-14 15:08:06 +00:00
const siteRes = this.isoData.site_res;
2023-05-14 23:49:55 +00:00
const siteView = siteRes?.site_view;
return (
<>
<Provider i18next={i18n}>
<div id="app">
2023-05-14 23:49:55 +00:00
{siteView && (
<Theme defaultTheme={siteView.local_site.default_theme} />
)}
<Navbar siteRes={siteRes} />
<div className="mt-4 p-0 fl-1">
<Switch>
2023-05-14 15:08:06 +00:00
{routes.map(({ path, component: RouteComponent }) => (
<Route
key={path}
path={path}
exact
component={routeProps => (
<ErrorGuard>
{RouteComponent &&
(isAuthPath(path ?? "") ? (
<AuthGuard>
<RouteComponent {...routeProps} />
</AuthGuard>
) : (
<RouteComponent {...routeProps} />
))}
</ErrorGuard>
)}
/>
))}
2023-05-14 15:08:06 +00:00
<Route component={ErrorPage} />
</Switch>
</div>
<Footer site={siteRes} />
</div>
</Provider>
</>
);
}
}