App.PollList = function PollList() { const [polls, setPolls] = React.useState([]); const [loading, setLoading] = React.useState(true); const loadPolls = () => { setLoading(true); App.API.get('polls?fingerprint=' + App.fingerprint).then(data => { setPolls(data); setLoading(false); }); }; React.useEffect(() => { loadPolls(); }, []); const handleDelete = (shareCode, title) => { if (!confirm('Delete poll "' + title + '"? All votes will be lost.')) return; App.API.post('polls/' + shareCode, { _action: 'delete', fingerprint: App.fingerprint, }) .then(() => loadPolls()) .catch(err => alert(err.message)); }; if (loading) return ; return (

Polls

Create Poll

Active polls for voting on race combinations

{polls.length === 0 ? (

No active polls yet.

Create Poll
) : (
{polls.map(poll => { var voteStatus = ''; if (typeof poll.user_voted !== 'undefined') { if (poll.user_voted === 0) voteStatus = 'poll-status-none'; else if (poll.user_voted >= poll.user_total) voteStatus = 'poll-status-complete'; else voteStatus = 'poll-status-partial'; } return (

{poll.title}

{poll.combo_count} combo{poll.combo_count != 1 ? 's' : ''} Created {new Date(poll.created_at).toLocaleDateString()} {(poll.creator_nickname || poll.creator_id) && ( by )} {typeof poll.user_voted !== 'undefined' && ( voteStatus === 'poll-status-complete' ? All voted : {poll.user_total - poll.user_voted} vote{poll.user_total - poll.user_voted !== 1 ? 's' : ''} remaining )}
{poll.combos && poll.combos.length > 0 && (
{poll.combos.map((combo, i) => (
{combo.track_name} {combo.car_names.length > 0 && ( — {combo.car_names.join(' / ')} )}
))}
)}
Vote Results {poll.creator_fingerprint === App.fingerprint && ( )}
); })}
)}
); };