const preact = require('preact'); const { connect } = require('preact-redux'); const actions = require('../actions'); const addState = connect( function receiveState(state) { const { ws, game, account, resolution, showNav, } = state; function sendGameReady() { ws.sendGameReady(game.id); } function sendInstanceState(instanceId) { if (!instanceId) return false; return ws.sendInstanceState(instanceId); } return { game, account, resolution, sendInstanceState, sendGameReady, showNav, }; }, function receiveDispatch(dispatch) { function quit() { dispatch(actions.setGame(null)); dispatch(actions.setInstance(null)); } function skip() { dispatch(actions.setSkip(true)); } function setShowNav(v) { return dispatch(actions.setShowNav(v)); } return { setShowNav, quit, skip }; } ); function GameFooter(props) { const { game, account, resolution, showNav, quit, skip, setShowNav, sendGameReady, sendInstanceState, } = props; if (!game) { return ( ); } const playerTeam = game.players.find(t => t.id === account.id); function quitClick() { sendInstanceState(game.instance); quit(); return true; } const quitBtn = ( ); const skipBtn = ( ); const readyBtn = ( ); const zero = Date.parse(game.phase_start); const now = Date.now(); const end = Date.parse(game.phase_end); const timerPct = ((now - zero) / (end - zero) * 100); const displayPct = resolution || game.phase === 'Finish' || !game.phase_end ? 0 : Math.min(timerPct, 100); const displayColour = playerTeam.ready ? 'forestgreen' : timerPct > 80 ? 'red' : 'whitesmoke'; const timerStyles = { width: `${displayPct}%`, background: displayColour, }; const timer = game.phase_end ? (
 
) : null; return ( ); } module.exports = addState(GameFooter);