App.Dashboard = function Dashboard({ user }) { const [data, setData] = React.useState(null); const [loading, setLoading] = React.useState(true); const [quote, setQuote] = React.useState(null); const quotesRef = React.useRef([]); React.useEffect(() => { App.API.get('dashboard?fingerprint=' + App.fingerprint) .then(d => { setData(d); setLoading(false); }) .catch(() => setLoading(false)); fetch('data/quotes.json') .then(r => r.json()) .then(quotes => { quotesRef.current = quotes; if (quotes.length > 0) { setQuote(quotes[Math.floor(Math.random() * quotes.length)]); } }) .catch(() => {}); }, []); function newQuote() { const quotes = quotesRef.current; if (quotes.length <= 1) return; let next; do { next = quotes[Math.floor(Math.random() * quotes.length)]; } while (next === quote); setQuote(next); } if (loading) return ; if (!data) return

Failed to load dashboard.

; const greeting = user && user.nickname ? 'Welcome back, ' + user.nickname + '!' : 'Welcome to I Race Builder!'; return (

{greeting}

{quote ? (

"{quote.text}" — {quote.author}

) : (

Your racing command center

)} {/* Quick Actions */}

Quick Actions

Create Race Combo Create Poll
{/* Polls Needing Your Vote */}

Polls Needing Your Vote

{data.pollsToVote.length === 0 ? (

You're all caught up!

) : (
{data.pollsToVote.map(poll => (

{poll.title}

{poll.comboCount} combo{poll.comboCount !== 1 ? 's' : ''} {poll.votesRemaining} vote{poll.votesRemaining !== 1 ? 's' : ''} remaining
{poll.combos && poll.combos.length > 0 && (
{poll.combos.map((combo, i) => (
{combo.track_name}
{combo.car_names.map((car, ci) => (
{car}
))}
))}
)} Vote Now
))}
)}
{/* Recent Results */}

Recent Results

{data.recentResults.length === 0 ? (

No poll results yet.

) : (
{data.recentResults.map(poll => (

{poll.title}

{poll.allResults && poll.allResults.length > 0 ? ( poll.allResults.map((combo, i) => (

#{combo.rank}: {combo.name} at {combo.trackName} {combo.voteCount > 0 && ( ({combo.avgRating.toFixed(1)} avg) )}

)) ) : (

No votes yet

)}
View Results
))}
)}
{/* Your Combos */}

Your Combos

{data.yourCombos.length === 0 ? (

You haven't created any combos yet.

) : ( <>
{data.yourCombos.map(combo => ( ))}
View All Combos )}
); };