From b27061e44a194e60fc112b09b87ea6e7841488c2 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Mon, 23 Mar 2026 18:56:32 +0200 Subject: [PATCH] feat: rewrite use-chat-session-state hook from Electric to Zero Replace @electric-sql/react useShape with @rocicorp/zero/react useQuery. Same Jotai atom update, same logic, same consumer contract. --- surfsense_web/hooks/use-chat-session-state.ts | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/surfsense_web/hooks/use-chat-session-state.ts b/surfsense_web/hooks/use-chat-session-state.ts index f3bdd7722..3c32c3d2a 100644 --- a/surfsense_web/hooks/use-chat-session-state.ts +++ b/surfsense_web/hooks/use-chat-session-state.ts @@ -1,27 +1,19 @@ "use client"; -import { useShape } from "@electric-sql/react"; import { useSetAtom } from "jotai"; import { useEffect } from "react"; import { chatSessionStateAtom } from "@/atoms/chat/chat-session-state.atom"; -import type { ChatSessionState } from "@/contracts/types/chat-session-state.types"; - -const ELECTRIC_URL = process.env.NEXT_PUBLIC_ELECTRIC_URL || "http://localhost:5133"; +import { queries } from "@/zero/queries"; +import { useQuery } from "@rocicorp/zero/react"; /** - * Syncs chat session state for a thread via Electric SQL. + * Syncs chat session state for a thread via Zero. * Call once per thread (in page.tsx). Updates global atom. */ export function useChatSessionStateSync(threadId: number | null) { const setSessionState = useSetAtom(chatSessionStateAtom); - const { data } = useShape({ - url: `${ELECTRIC_URL}/v1/shape`, - params: { - table: "chat_session_state", - where: `thread_id = ${threadId ?? -1}`, - }, - }); + const [row] = useQuery(queries.chatSession.byThread({ threadId: threadId ?? -1 })); useEffect(() => { if (!threadId) { @@ -29,11 +21,10 @@ export function useChatSessionStateSync(threadId: number | null) { return; } - const row = data?.[0]; setSessionState({ threadId, - isAiResponding: !!row?.ai_responding_to_user_id, - respondingToUserId: row?.ai_responding_to_user_id ?? null, + isAiResponding: !!row?.aiRespondingToUserId, + respondingToUserId: row?.aiRespondingToUserId ?? null, }); - }, [threadId, data, setSessionState]); + }, [threadId, row, setSessionState]); }