import React, { memo } from 'react'; import { IMAGES } from '../../utils/constants'; const bombSrc = area => { if (null === area) return null; const vert = ['left', 'center', 'right'][area[0]] ?? null; const hor = ['top', 'middle', 'bottom'][area[1]] ?? null; if (null === vert || null === hor) return IMAGES.bombEmpty; return IMAGES.bombPos(hor, vert); }; const GridField = memo(function GridField({ cell, onClick, onMouseEnter }) { const { currentImage, currentObj, active, lastClickedRed, lastClickedBlue, bombTargetArea } = cell; const fieldClass = 'field' + (active ? ' active' : '') + (active && 'm' === currentObj ? ' mine' : '') + ' color-' + currentObj; const inner = isNaN(currentImage) ? (
) : currentImage ?
{currentImage}
: null; const bSrc = bombSrc(bombTargetArea); const showLast = lastClickedRed || lastClickedBlue; const lastClass = 'field-' + (lastClickedRed ? 'red' : 'blue') + '-last last-clicked'; return (
{bSrc && } {showLast && }
{inner}
); }); export default GridField;