mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 01:15:28 +00:00
chore: deprecate RevoltClient context
This commit is contained in:
@@ -8,12 +8,12 @@ import { Preloader, UIProvider } from "@revoltchat/ui";
|
||||
|
||||
import { hydrateState } from "../mobx/State";
|
||||
|
||||
import Binder from "../controllers/client/jsx/Binder";
|
||||
import ModalRenderer from "../controllers/modals/ModalRenderer";
|
||||
import Locale from "./Locale";
|
||||
import Theme from "./Theme";
|
||||
import { history } from "./history";
|
||||
import Intermediate from "./intermediate/Intermediate";
|
||||
import Client from "./revoltjs/RevoltClient";
|
||||
import SyncManager from "./revoltjs/SyncManager";
|
||||
|
||||
const uiContext = {
|
||||
@@ -41,10 +41,10 @@ export default function Context({ children }: { children: Children }) {
|
||||
<UIProvider value={uiContext}>
|
||||
<Locale>
|
||||
<Intermediate>
|
||||
<Client>
|
||||
<Binder>
|
||||
{children}
|
||||
<SyncManager />
|
||||
</Client>
|
||||
{<SyncManager />}
|
||||
</Binder>
|
||||
</Intermediate>
|
||||
<ModalRenderer />
|
||||
</Locale>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Redirect } from "react-router-dom";
|
||||
|
||||
import { useSession } from "../../controllers/client/ClientController";
|
||||
import { clientController } from "../../controllers/client/ClientController";
|
||||
|
||||
interface Props {
|
||||
auth?: boolean;
|
||||
@@ -9,16 +10,17 @@ interface Props {
|
||||
children: Children;
|
||||
}
|
||||
|
||||
export const CheckAuth = (props: Props) => {
|
||||
const session = useSession();
|
||||
export const CheckAuth = observer((props: Props) => {
|
||||
const loggedIn = clientController.isLoggedIn();
|
||||
|
||||
if (props.auth && !session?.ready) {
|
||||
// Redirect if logged out on authenticated page or vice-versa.
|
||||
if (props.auth && !loggedIn) {
|
||||
if (props.blockRender) return null;
|
||||
return <Redirect to="/login" />;
|
||||
} else if (!props.auth && session?.ready) {
|
||||
} else if (!props.auth && loggedIn) {
|
||||
if (props.blockRender) return null;
|
||||
return <Redirect to="/" />;
|
||||
}
|
||||
|
||||
return <>{props.children}</>;
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
import { observer } from "mobx-react-lite";
|
||||
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
import { Preloader } from "@revoltchat/ui";
|
||||
|
||||
import { useApplicationState } from "../../mobx/State";
|
||||
|
||||
import { clientController } from "../../controllers/client/ClientController";
|
||||
|
||||
type Props = {
|
||||
children: Children;
|
||||
};
|
||||
|
||||
export default observer(({ children }: Props) => {
|
||||
const session = clientController.getActiveSession();
|
||||
if (session) {
|
||||
if (!session.ready) return <Preloader type="spinner" />;
|
||||
|
||||
const client = session.client!;
|
||||
const state = useApplicationState();
|
||||
useEffect(() => state.registerListeners(client), [state, client]);
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
});
|
||||
Reference in New Issue
Block a user