import React from 'react'; import { useGame } from '../../contexts/GameContext'; import User from './User'; const UserControl = ({ resign }) => { const { webPlayer, activePlayer, mines, foundMines, red, blue, onBombToggle } = useGame(); const activeColor = activePlayer ? 'blue' : 'red'; const resignClass = 'resign' + (activeColor !== webPlayer ? ' disabled' : ''); const minesClass = 'active-mines' + (foundMines ? ' found-mine' : ''); const handleBombClick = (color, player) => { const p = 'red' === color ? red : blue; if (p.haveBomb && p.enabledBomb && activePlayer === player) { onBombToggle(); } }; return (
handleBombClick('blue', 1)} />
{mines}
handleBombClick('red', 0)} />
); } export default UserControl;