import { useEffect, useRef } from "react"; // The help widget can raise a support request from any screen, including an open Support list, so the // list hears about it rather than waiting for the person to leave and come back. const SUPPORT_TICKET_RAISED = "akashic:support-ticket-raised"; export const announceSupportTicketRaised = (): void => { window.dispatchEvent(new Event(SUPPORT_TICKET_RAISED)); }; export const useSupportTicketRaised = (reread: () => void): void => { const latest = useRef(reread); latest.current = reread; useEffect(() => { const onRaised = () => latest.current(); window.addEventListener(SUPPORT_TICKET_RAISED, onRaised); return () => window.removeEventListener(SUPPORT_TICKET_RAISED, onRaised); }, []); };