|
|
@@ -1,11 +1,12 @@
|
|
|
import { registerCustomElement } from "ojs/ojvcomponent";
|
|
|
import { FunctionComponent } from "preact";
|
|
|
-import { useEffect } from "preact/hooks";
|
|
|
+import { useEffect, useState } from "preact/hooks";
|
|
|
import { Footer } from "./footer";
|
|
|
import { Header } from "./header";
|
|
|
import { Content } from "./content/index";
|
|
|
import { useLogin } from "../hooks/useLogin";
|
|
|
import { useQuery, Plugin, NavigationItem } from "../hooks/useQuery";
|
|
|
+import { BrowserRouter, NavigateFunction, Route, Routes } from "react-router-dom";
|
|
|
|
|
|
import Context = require("ojs/ojcontext");
|
|
|
|
|
|
@@ -16,9 +17,15 @@ type Props = Readonly<{
|
|
|
|
|
|
const AppComponent: FunctionComponent<Props> = ({ appName = "OCC" }) => {
|
|
|
const { userLogin, login, logout, accessToken } = useLogin();
|
|
|
+
|
|
|
const { result: plugins } = useQuery<Plugin[]>("/plugins", accessToken);
|
|
|
const { result: navigations } = useQuery<NavigationItem[]>("/navigations", accessToken);
|
|
|
|
|
|
+ const [navigate, setNavigate] = useState<NavigateFunction>();
|
|
|
+ const getNavigateRef = (navigate: NavigateFunction) => {
|
|
|
+ setNavigate(_ => navigate);
|
|
|
+ }
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
Context.getPageContext().getBusyContext().applicationBootstrapComplete();
|
|
|
}, []);
|
|
|
@@ -30,10 +37,17 @@ const AppComponent: FunctionComponent<Props> = ({ appName = "OCC" }) => {
|
|
|
userLogin={userLogin}
|
|
|
login={login}
|
|
|
logout={logout}
|
|
|
+ navigate={navigate}
|
|
|
navigations={navigations}
|
|
|
plugins={plugins}
|
|
|
/>
|
|
|
- <Content userLogin={userLogin} plugins={plugins} />
|
|
|
+ <BrowserRouter>
|
|
|
+ <Routes>
|
|
|
+ {(plugins ?? [undefined]).map(p => {
|
|
|
+ return (<Route path={p?.path ?? "/"} element={<Content plugin={p} navigateRef={getNavigateRef}/>} />);
|
|
|
+ })}
|
|
|
+ </Routes>
|
|
|
+ </BrowserRouter>
|
|
|
<Footer />
|
|
|
</div>
|
|
|
);
|