import { useState, useEffect, useRef } from 'react' interface ProposalModalProps { onClose: () => void } export function ProposalModal({ onClose }: ProposalModalProps) { const [text, setText] = useState('') const [author, setAuthor] = useState('') const [proposals, setProposals] = useState('') const [submitting, setSubmitting] = useState(false) const [submitted, setSubmitted] = useState(false) const overlayRef = useRef(null) const textareaRef = useRef(null) useEffect(() => { fetch('/api/proposals') .then(r => r.json()) .then(d => setProposals(d.content || '')) .catch(() => {}) }, [submitted]) useEffect(() => { textareaRef.current?.focus() }, []) useEffect(() => { const handleKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } document.addEventListener('keydown', handleKey) return () => document.removeEventListener('keydown', handleKey) }, [onClose]) const handleSubmit = async () => { if (!text.trim()) return setSubmitting(true) try { const res = await fetch('/api/proposals', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: text.trim(), author: author.trim() || undefined }), }) if (res.ok) { setText('') setSubmitted(s => !s) } } catch { } finally { setSubmitting(false) } } return (
{ if (e.target === overlayRef.current) onClose() }} >

Návrhy na vylepšení

setAuthor(e.target.value)} placeholder="Vase jmeno (nepovinne)" className="w-full bg-slate-900 border border-slate-600 rounded px-3 py-1.5 text-xs text-slate-200 placeholder-slate-500 outline-none focus:border-blue-500 transition-colors mb-2" />