mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
Add MobX store, create observable User.
This commit is contained in:
@@ -14,6 +14,7 @@ import { AuthState } from "../../redux/reducers/auth";
|
||||
|
||||
import Preloader from "../../components/ui/Preloader";
|
||||
|
||||
import { useData } from "../../mobx/State";
|
||||
import { Children } from "../../types/Preact";
|
||||
import { useIntermediate } from "../intermediate/Intermediate";
|
||||
import { registerEvents, setReconnectDisallowed } from "./events";
|
||||
@@ -157,9 +158,10 @@ function Context({ auth, children }: Props) {
|
||||
};
|
||||
}, [client, auth.active]);
|
||||
|
||||
const store = useData();
|
||||
useEffect(
|
||||
() => registerEvents({ operations }, setStatus, client),
|
||||
[client],
|
||||
() => registerEvents({ operations }, setStatus, client, store),
|
||||
[client, store],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -5,6 +5,8 @@ import { StateUpdater } from "preact/hooks";
|
||||
|
||||
import { dispatch } from "../../redux";
|
||||
|
||||
import { DataStore } from "../../mobx";
|
||||
import { useData } from "../../mobx/State";
|
||||
import { ClientOperations, ClientStatus } from "./RevoltClient";
|
||||
|
||||
export var preventReconnect = false;
|
||||
@@ -18,6 +20,7 @@ export function registerEvents(
|
||||
{ operations }: { operations: ClientOperations },
|
||||
setStatus: StateUpdater<ClientStatus>,
|
||||
client: Client,
|
||||
store: DataStore,
|
||||
) {
|
||||
function attemptReconnect() {
|
||||
if (preventReconnect) return;
|
||||
@@ -45,6 +48,7 @@ export function registerEvents(
|
||||
},
|
||||
|
||||
packet: (packet: ClientboundNotification) => {
|
||||
store.packet(packet);
|
||||
switch (packet.type) {
|
||||
case "ChannelStartTyping": {
|
||||
if (packet.user === client.user?._id) return;
|
||||
|
||||
@@ -5,7 +5,7 @@ import Collection from "revolt.js/dist/maps/Collection";
|
||||
|
||||
import { useContext, useEffect, useState } from "preact/hooks";
|
||||
|
||||
//#region Hooks v1
|
||||
//#region Hooks v1 (deprecated)
|
||||
import { AppContext } from "./RevoltClient";
|
||||
|
||||
export interface HookContext {
|
||||
@@ -238,7 +238,7 @@ export function useServerPermission(id: string, context?: HookContext) {
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region Hooks v2
|
||||
//#region Hooks v2 (deprecated)
|
||||
type CollectionKeys = Exclude<
|
||||
keyof PickProperties<Client, Collection<any>>,
|
||||
undefined
|
||||
@@ -249,7 +249,7 @@ interface Depedency {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export function useData<T>(
|
||||
export function useDataDeprecated<T>(
|
||||
cb: (client: Client) => T,
|
||||
dependencies: Depedency[],
|
||||
): T {
|
||||
|
||||
Reference in New Issue
Block a user