Next.js 16 + Drizzle/SQLite (matching ~/project-claude conventions), SSE-based realtime updates, admin dashboard with status columns, ticket thread view, Telegram long-polling integration (inbound + outbound), token-based customer portal, Docker Compose packaging. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcXH24ky6zjk2UyK5oZUPH
25 lines
727 B
TypeScript
25 lines
727 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
import type { TicketEvent } from "@/lib/events/bus";
|
|
|
|
/** Subscribes to a ticket-events SSE endpoint for the lifetime of the component. */
|
|
export function useTicketEvents(url: string, onEvent: (event: TicketEvent) => void) {
|
|
const handlerRef = useRef(onEvent);
|
|
useLayoutEffect(() => {
|
|
handlerRef.current = onEvent;
|
|
});
|
|
|
|
useEffect(() => {
|
|
const source = new EventSource(url);
|
|
source.onmessage = (e) => {
|
|
try {
|
|
handlerRef.current(JSON.parse(e.data) as TicketEvent);
|
|
} catch {
|
|
// malformed payload — ignore rather than crash the subscription
|
|
}
|
|
};
|
|
return () => source.close();
|
|
}, [url]);
|
|
}
|