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:
@@ -58,8 +58,9 @@ class ClientController {
|
||||
}
|
||||
|
||||
@action pickNextSession() {
|
||||
this.current =
|
||||
this.current ?? this.sessions.keys().next().value ?? null;
|
||||
this.switchAccount(
|
||||
this.current ?? this.sessions.keys().next().value ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,6 +83,15 @@ class ClientController {
|
||||
return this.sessions.get(this.current!);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently ready client
|
||||
* @returns Ready Client
|
||||
*/
|
||||
@computed getReadyClient() {
|
||||
const session = this.getActiveSession();
|
||||
return session && session.ready ? session.client! : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an unauthenticated instance of the Revolt.js Client
|
||||
* @returns API Client
|
||||
@@ -111,7 +121,15 @@ class ClientController {
|
||||
* @returns Whether we are logged in
|
||||
*/
|
||||
@computed isLoggedIn() {
|
||||
return this.current === null;
|
||||
return this.current !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we are currently ready
|
||||
* @returns Whether we are ready to render
|
||||
*/
|
||||
@computed isReady() {
|
||||
return this.getActiveSession()?.ready;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,6 +145,7 @@ class ClientController {
|
||||
|
||||
const session = new Session();
|
||||
this.sessions.set(user_id, session);
|
||||
this.pickNextSession();
|
||||
|
||||
session
|
||||
.emit({
|
||||
@@ -144,8 +163,6 @@ class ClientController {
|
||||
session.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
this.pickNextSession();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -270,6 +270,6 @@ export default class Session {
|
||||
* @returns Boolean
|
||||
*/
|
||||
@computed get ready() {
|
||||
return this.client?.user;
|
||||
return !!this.client?.user;
|
||||
}
|
||||
}
|
||||
|
||||
27
src/controllers/client/jsx/Binder.tsx
Normal file
27
src/controllers/client/jsx/Binder.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { observer } from "mobx-react-lite";
|
||||
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
import { Preloader } from "@revoltchat/ui";
|
||||
|
||||
import { state } from "../../../mobx/State";
|
||||
|
||||
import { clientController } from "../ClientController";
|
||||
|
||||
/**
|
||||
* Prevent render until the client is ready to display.
|
||||
* Also binds listeners from state to the current client.
|
||||
*/
|
||||
const Binder: React.FC = ({ children }) => {
|
||||
const client = clientController.getReadyClient();
|
||||
useEffect(() => state.registerListeners(client!), [client]);
|
||||
|
||||
// Block render if client is getting ready to work.
|
||||
if (clientController.isLoggedIn() && !clientController.isReady()) {
|
||||
return <Preloader type="spinner" />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default observer(Binder);
|
||||
Reference in New Issue
Block a user