Pete Dunn
Initial commit for HF deployment
1187b53
Raw
History Blame Contribute Delete
812 Bytes
import { useEffect } from "react";
const APP_COMMAND_EVENT = "masters_toolkit_app_command_v1";
export function dispatchAppCommand(command: string): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new CustomEvent(APP_COMMAND_EVENT, { detail: { command } }));
}
export function useAppCommandListener(onCommand: (command: string) => void): void {
useEffect(() => {
const handler = (event: Event) => {
const custom = event as CustomEvent<{ command?: string }>;
const command = String(custom.detail?.command || "").trim();
if (!command) return;
onCommand(command);
};
window.addEventListener(APP_COMMAND_EVENT, handler as EventListener);
return () => window.removeEventListener(APP_COMMAND_EVENT, handler as EventListener);
}, [onCommand]);
}