import { useEffect, useRef, useState } from 'react'; import { Modal } from './Modal'; import { useStore } from '../lib/store'; import { dialogStore, resolveConfirm, resolvePrompt } from '../lib/dialog'; import { t } from '../i18n'; // Renders the active custom dialog (confirm/prompt). Mounted once at the app // root; see lib/dialog.ts for the confirmDialog/promptDialog helpers. export function DialogHost() { const { current } = useStore(dialogStore); const [text, setText] = useState(''); const inputRef = useRef(null); // Seed the prompt field with its initial value and focus it each time a // new prompt opens. useEffect(() => { if (current && current.kind === 'prompt') { setText(current.initial || ''); // Focus after the modal mounts. setTimeout(() => inputRef.current?.focus(), 0); } }, [current]); if (!current) return null; if (current.kind === 'confirm') { return ( resolveConfirm(false)} footer={ <> } >

{current.message}

); } return ( resolvePrompt(null)} footer={ <> } >
{ e.preventDefault(); resolvePrompt(text.trim() || null); }} > {current.message &&

{current.message}

} setText(e.target.value)} placeholder={current.placeholder} autoComplete="off" />
); }