mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 01:15:28 +00:00
chore(refactor): remove SyncManager
This commit is contained in:
@@ -6,7 +6,7 @@ import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
import { Preloader, UIProvider } from "@revoltchat/ui";
|
||||
|
||||
import { hydrateState } from "../mobx/State";
|
||||
import { state } from "../mobx/State";
|
||||
|
||||
import Binder from "../controllers/client/jsx/Binder";
|
||||
import ModalRenderer from "../controllers/modals/ModalRenderer";
|
||||
@@ -14,7 +14,6 @@ import Locale from "./Locale";
|
||||
import Theme from "./Theme";
|
||||
import { history } from "./history";
|
||||
import Intermediate from "./intermediate/Intermediate";
|
||||
import SyncManager from "./revoltjs/SyncManager";
|
||||
|
||||
const uiContext = {
|
||||
Link,
|
||||
@@ -31,7 +30,7 @@ export default function Context({ children }: { children: Children }) {
|
||||
const [ready, setReady] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
hydrateState().then(() => setReady(true));
|
||||
state.hydrate().then(() => setReady(true));
|
||||
}, []);
|
||||
|
||||
if (!ready) return <Preloader type="spinner" />;
|
||||
@@ -42,7 +41,6 @@ export default function Context({ children }: { children: Children }) {
|
||||
<Locale>
|
||||
<Intermediate>
|
||||
{children}
|
||||
<SyncManager />
|
||||
<Binder />
|
||||
</Intermediate>
|
||||
<ModalRenderer />
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
* This file monitors changes to settings and syncs them to the server.
|
||||
*/
|
||||
import { ClientboundNotification } from "revolt.js";
|
||||
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
import { reportError } from "../../lib/ErrorBoundary";
|
||||
|
||||
import { useApplicationState } from "../../mobx/State";
|
||||
|
||||
import {
|
||||
useClient,
|
||||
useSession,
|
||||
} from "../../controllers/client/ClientController";
|
||||
|
||||
export default function SyncManager() {
|
||||
const client = useClient();
|
||||
const session = useSession();
|
||||
const state = useApplicationState();
|
||||
|
||||
// Sync settings from Revolt.
|
||||
useEffect(() => {
|
||||
if (session?.ready) {
|
||||
state.sync
|
||||
.pull(session.client!)
|
||||
.catch(console.error)
|
||||
.finally(() => state.changelog.checkForUpdates());
|
||||
}
|
||||
}, [session?.ready]);
|
||||
|
||||
// Take data updates from Revolt.
|
||||
useEffect(() => {
|
||||
if (!client) return;
|
||||
function onPacket(packet: ClientboundNotification) {
|
||||
if (packet.type === "UserSettingsUpdate") {
|
||||
try {
|
||||
state.sync.apply(packet.update);
|
||||
} catch (err) {
|
||||
reportError(err as any, "failed_sync_apply");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client.addListener("packet", onPacket);
|
||||
return () => client.removeListener("packet", onPacket);
|
||||
}, [client]);
|
||||
|
||||
return <></>;
|
||||
}
|
||||
Reference in New Issue
Block a user