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

61 lines
1.9 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";
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> {
private isoData = 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;
const siteView = siteRes.site_view;
return (
<>
<Provider i18next={i18n}>
<div id="app">
2022-11-09 19:53:07 +00:00
<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>
</>
);
}
}