2026-04-12 13:14:18 +02:00
|
|
|
import { useEffect } from 'react'
|
|
|
|
|
import {
|
|
|
|
|
AI_PROMPT_QUEUED_EVENT,
|
|
|
|
|
takeQueuedAiPrompt,
|
|
|
|
|
type QueuedAiPrompt,
|
|
|
|
|
} from '../utils/aiPromptBridge'
|
|
|
|
|
|
|
|
|
|
export function useQueuedAiPrompt(
|
|
|
|
|
onPrompt: (prompt: QueuedAiPrompt) => void,
|
2026-05-26 16:26:51 +02:00
|
|
|
enabled = true,
|
2026-04-12 13:14:18 +02:00
|
|
|
) {
|
|
|
|
|
useEffect(() => {
|
2026-05-26 16:26:51 +02:00
|
|
|
if (!enabled) return
|
|
|
|
|
|
2026-04-12 13:14:18 +02:00
|
|
|
const consumePrompt = () => {
|
|
|
|
|
const queuedPrompt = takeQueuedAiPrompt()
|
|
|
|
|
if (queuedPrompt) onPrompt(queuedPrompt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
consumePrompt()
|
|
|
|
|
window.addEventListener(AI_PROMPT_QUEUED_EVENT, consumePrompt)
|
|
|
|
|
return () => window.removeEventListener(AI_PROMPT_QUEUED_EVENT, consumePrompt)
|
2026-05-26 16:26:51 +02:00
|
|
|
}, [enabled, onPrompt])
|
2026-04-12 13:14:18 +02:00
|
|
|
}
|