App.CreatePoll = function CreatePoll() { const [title, setTitle] = React.useState(''); const [combos, setCombos] = React.useState([]); const [selectedIds, setSelectedIds] = React.useState([]); const [loading, setLoading] = React.useState(true); const [saving, setSaving] = React.useState(false); const [error, setError] = React.useState(''); const [shareCode, setShareCode] = React.useState(null); const [generating, setGenerating] = React.useState(false); const [showNamePrompt, setShowNamePrompt] = React.useState(false); const titleInputRef = React.useRef(null); React.useEffect(() => { App.API.get('combos?limit=50').then(data => { setCombos(data.combos); setLoading(false); }); }, []); const toggleCombo = (id) => { setSelectedIds(prev => prev.includes(id) ? prev.filter(x => x !== id) : [...prev, id] ); }; const generateName = () => { setGenerating(true); App.API.get('name-generator?type=poll&count=1').then(data => { if (data.names && data.names.length > 0) { setTitle(data.names[0]); } setGenerating(false); }).catch(() => { setGenerating(false); }); }; const handleSubmit = () => { setError(''); if (!title.trim()) { setShowNamePrompt(true); return; } if (selectedIds.length === 0) { setError('Please select at least one combo'); return; } setSaving(true); App.API.post('polls', { title: title.trim(), comboIds: selectedIds, fingerprint: App.fingerprint, }).then(data => { setShareCode(data.shareCode); setSaving(false); }).catch(err => { setError(err.message); setSaving(false); }); }; const handleNamePromptEnter = () => { setShowNamePrompt(false); if (titleInputRef.current) titleInputRef.current.focus(); }; const handleNamePromptGenerate = () => { setShowNamePrompt(false); generateName(); }; const copyLink = () => { const url = window.location.origin + '/poll/' + shareCode; navigator.clipboard.writeText(url).then(() => { alert('Link copied to clipboard!'); }); }; if (shareCode) { const pollUrl = window.location.origin + '/poll/' + shareCode; return (

Poll Created!

Share this link with your friends:

Vote Now View Results
); } if (loading) return ; return (

Create Poll

Select combos to include in your poll, then share the link

{error &&
{error}
}
setTitle(e.target.value)} maxLength={200} />

Select Combos ({selectedIds.length} selected)

{combos.length === 0 ? (

No combos available. Create some combos first!

Create Race Combo
) : (
{combos.map(combo => ( ))}
)} {showNamePrompt && ( setShowNamePrompt(false)} /> )}
); };