2022-05-27 14:57:41 -04:00
|
|
|
import { BrowserRouter as Router, Link } from "react-router-dom";
|
2021-06-18 12:57:08 -04:00
|
|
|
|
2022-05-27 14:57:41 -04:00
|
|
|
import { ContextMenuTrigger } from "preact-context-menu";
|
|
|
|
import { Text } from "preact-i18n";
|
2021-12-23 21:05:18 -05:00
|
|
|
import { useEffect, useState } from "preact/hooks";
|
|
|
|
|
2022-06-12 10:07:30 -04:00
|
|
|
import { Preloader, UIProvider } from "@revoltchat/ui";
|
2022-05-27 14:57:41 -04:00
|
|
|
|
2021-12-23 21:05:18 -05:00
|
|
|
import { hydrateState } from "../mobx/State";
|
|
|
|
|
2021-06-18 12:57:08 -04:00
|
|
|
import Locale from "./Locale";
|
|
|
|
import Theme from "./Theme";
|
2021-07-05 06:23:23 -04:00
|
|
|
import Intermediate from "./intermediate/Intermediate";
|
2022-06-10 11:52:12 -04:00
|
|
|
import ModalRenderer from "./modals/ModalRenderer";
|
2021-07-05 06:23:23 -04:00
|
|
|
import Client from "./revoltjs/RevoltClient";
|
2021-12-24 07:00:24 -05:00
|
|
|
import SyncManager from "./revoltjs/SyncManager";
|
2021-06-18 12:57:08 -04:00
|
|
|
|
2022-06-12 10:07:30 -04:00
|
|
|
const uiContext = {
|
|
|
|
Link,
|
|
|
|
Text: Text as any,
|
|
|
|
Trigger: ContextMenuTrigger,
|
|
|
|
emitAction: () => {},
|
|
|
|
};
|
|
|
|
|
2021-12-10 07:53:41 -05:00
|
|
|
/**
|
|
|
|
* This component provides all of the application's context layers.
|
|
|
|
* @param param0 Provided children
|
|
|
|
*/
|
2021-06-18 12:57:08 -04:00
|
|
|
export default function Context({ children }: { children: Children }) {
|
2021-12-23 21:05:18 -05:00
|
|
|
const [ready, setReady] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
hydrateState().then(() => setReady(true));
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!ready) return <Preloader type="spinner" />;
|
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
2021-09-10 18:03:06 -04:00
|
|
|
<Router basename={import.meta.env.BASE_URL}>
|
2022-06-12 10:07:30 -04:00
|
|
|
<UIProvider value={uiContext}>
|
|
|
|
<Locale>
|
|
|
|
<Intermediate>
|
|
|
|
<Client>
|
|
|
|
{children}
|
|
|
|
<SyncManager />
|
|
|
|
</Client>
|
|
|
|
</Intermediate>
|
|
|
|
<ModalRenderer />
|
|
|
|
</Locale>
|
|
|
|
</UIProvider>
|
2021-12-23 16:43:11 -05:00
|
|
|
<Theme />
|
2021-07-05 06:25:20 -04:00
|
|
|
</Router>
|
|
|
|
);
|
2021-06-18 12:57:08 -04:00
|
|
|
}
|