mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2026-01-05 22:54:23 +01:00
perf: refactor sse handleing
This commit is contained in:
33
src/app/components/SSEEventListeners.tsx
Normal file
33
src/app/components/SSEEventListeners.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useSetAtom } from "jotai";
|
||||
import type { FC, PropsWithChildren } from "react";
|
||||
import { projectDetailQuery, sessionDetailQuery } from "../../lib/api/queries";
|
||||
import { useServerEventListener } from "../../lib/sse/hook/useServerEventListener";
|
||||
import { aliveTasksAtom } from "../projects/[projectId]/sessions/[sessionId]/store/aliveTasksAtom";
|
||||
|
||||
export const SSEEventListeners: FC<PropsWithChildren> = ({ children }) => {
|
||||
const queryClient = useQueryClient();
|
||||
const setAliveTasks = useSetAtom(aliveTasksAtom);
|
||||
|
||||
useServerEventListener("sessionListChanged", async (event) => {
|
||||
// invalidate session list
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: projectDetailQuery(event.projectId).queryKey,
|
||||
});
|
||||
});
|
||||
|
||||
useServerEventListener("sessionChanged", async (event) => {
|
||||
// invalidate session detail
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: sessionDetailQuery(event.projectId, event.sessionId).queryKey,
|
||||
});
|
||||
});
|
||||
|
||||
useServerEventListener("taskChanged", async (event) => {
|
||||
setAliveTasks(event.aliveTasks);
|
||||
});
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useServerEvents } from "@/hooks/useServerEvents";
|
||||
|
||||
interface ServerEventsProviderProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function ServerEventsProvider({ children }: ServerEventsProviderProps) {
|
||||
useServerEvents();
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user