forked from abner/for-legacy-web
Context Menus: Add "mark as unread" back.
Servers: Fix various issues relating to voice channels.
This commit is contained in:
@@ -104,6 +104,16 @@ export function registerEvents({
|
||||
client.addListener(listener, (listenerFunc as any)[listener]);
|
||||
}
|
||||
|
||||
function logMutation(target: string, key: string) {
|
||||
console.log('(o) Object mutated', target, '\nChanged:', key);
|
||||
}
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
client.users.addListener('mutation', logMutation);
|
||||
client.servers.addListener('mutation', logMutation);
|
||||
client.channels.addListener('mutation', logMutation);
|
||||
}
|
||||
|
||||
const online = () => {
|
||||
if (operations.ready()) {
|
||||
setStatus(ClientStatus.RECONNECTING);
|
||||
@@ -128,6 +138,12 @@ export function registerEvents({
|
||||
client.removeListener(listener, (listenerFunc as any)[listener]);
|
||||
}
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
client.users.removeListener('mutation', logMutation);
|
||||
client.servers.removeListener('mutation', logMutation);
|
||||
client.channels.removeListener('mutation', logMutation);
|
||||
}
|
||||
|
||||
window.removeEventListener("online", online);
|
||||
window.removeEventListener("offline", offline);
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface HookContext {
|
||||
export function useForceUpdate(context?: HookContext): HookContext {
|
||||
const client = useContext(AppContext);
|
||||
if (context) return context;
|
||||
const H = useState(undefined);
|
||||
/*const H = useState(undefined);
|
||||
var updateState: (_: undefined) => void;
|
||||
if (Array.isArray(H)) {
|
||||
let [, u] = H;
|
||||
@@ -20,14 +20,16 @@ export function useForceUpdate(context?: HookContext): HookContext {
|
||||
console.warn('Failed to construct using useState.');
|
||||
console.warn(H);
|
||||
updateState = ()=>{};
|
||||
}
|
||||
return { client, forceUpdate: useCallback(() => updateState(undefined), []) };
|
||||
}*/
|
||||
|
||||
const [, updateState] = useState(0);
|
||||
return { client, forceUpdate: () => updateState(Math.random()) };
|
||||
}
|
||||
|
||||
function useObject(type: string, id?: string | string[], context?: HookContext) {
|
||||
const ctx = useForceUpdate(context);
|
||||
|
||||
function mutation(target: string) {
|
||||
function update(target: any) {
|
||||
if (typeof id === 'string' ? target === id :
|
||||
Array.isArray(id) ? id.includes(target) : true) {
|
||||
ctx.forceUpdate();
|
||||
@@ -36,8 +38,8 @@ function useObject(type: string, id?: string | string[], context?: HookContext)
|
||||
|
||||
const map = (ctx.client as any)[type];
|
||||
useEffect(() => {
|
||||
map.addListener("update", mutation);
|
||||
return () => map.removeListener("update", mutation);
|
||||
map.addListener("update", update);
|
||||
return () => map.removeListener("update", update);
|
||||
}, [id]);
|
||||
|
||||
return typeof id === 'string' ? map.get(id)
|
||||
|
||||
Reference in New Issue
Block a user