free agents
This commit is contained in:
@@ -2,12 +2,9 @@ import { useEffect, useRef } from "react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { Logger } from "@/lib/logger";
|
||||
import { useAuth } from "@/contexts/auth-context";
|
||||
import { tournamentKeys, tournamentQueries } from "@/features/tournaments/queries";
|
||||
import { tournamentQueries } from "@/features/tournaments/queries";
|
||||
import { reactionKeys, reactionQueries } from "@/features/reactions/queries";
|
||||
|
||||
let newIdeasAvailable = false;
|
||||
let newIdeasCallbacks: (() => void)[] = [];
|
||||
|
||||
const logger = new Logger('ServerEvents');
|
||||
|
||||
type SSEEvent = {
|
||||
@@ -19,45 +16,19 @@ type EventHandler = (event: SSEEvent, queryClient: ReturnType<typeof useQueryCli
|
||||
|
||||
const eventHandlers: Record<string, EventHandler> = {
|
||||
"connected": () => {
|
||||
logger.info("ServerEvents | New Connection");
|
||||
logger.info("New Connection");
|
||||
},
|
||||
|
||||
"ping": () => {},
|
||||
|
||||
"test": (event, queryClient) => {
|
||||
|
||||
},
|
||||
|
||||
"match": (event, queryClient) => {
|
||||
queryClient.invalidateQueries(tournamentQueries.details(event.tournamentId))
|
||||
queryClient.invalidateQueries(tournamentQueries.current())
|
||||
},
|
||||
|
||||
"reaction": (event, queryClient) => {
|
||||
queryClient.invalidateQueries(reactionQueries.match(event.matchId));
|
||||
queryClient.setQueryData(reactionKeys.match(event.matchId), () => event.reactions);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export function getNewIdeasAvailable(): boolean {
|
||||
return newIdeasAvailable;
|
||||
}
|
||||
|
||||
export function clearNewIdeasAvailable(): void {
|
||||
newIdeasAvailable = false;
|
||||
}
|
||||
|
||||
export function subscribeToNewIdeas(callback: () => void): () => void {
|
||||
newIdeasCallbacks.push(callback);
|
||||
return () => {
|
||||
const index = newIdeasCallbacks.indexOf(callback);
|
||||
if (index > -1) {
|
||||
newIdeasCallbacks.splice(index, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function useServerEvents() {
|
||||
const queryClient = useQueryClient();
|
||||
const { user } = useAuth();
|
||||
|
||||
Reference in New Issue
Block a user