const preact = require('preact'); const { connect } = require('preact-redux'); const range = require('lodash/range'); const shapes = require('./shapes'); const addState = connect(({ vboxHighlight }) => ({ vboxHighlight })); class storeElement extends preact.Component { shouldComponentUpdate(newProps) { if (newProps.clearVboxSelected !== this.props.clearVboxSelected) return true; if (newProps.setVboxSelected !== this.props.setVboxSelected) return true; if (newProps.vbox !== this.props.vbox) return true; if (newProps.vboxHighlight !== this.props.vboxHighlight) return true; if (newProps.vboxHover !== this.props.vboxHover) return true; if (newProps.vboxSelected !== this.props.vboxSelected) return true; return false; } render(props) { const { // passed props clearVboxSelected, setVboxSelected, vbox, vboxHover, vboxSelected, // connect state props vboxHighlight, } = props; const { storeSelect, stashSelect } = vboxSelected; function availableBtn(v, group, index) { if (!v) return ; const selected = storeSelect.length && storeSelect.some(vs => vs[0] === group && vs[1] === index); const notValidCombo = vboxHighlight && !vboxHighlight.includes(v); function onClick(e) { e.stopPropagation(); if (storeSelect.length && storeSelect.some(vs => vs[0] === group && vs[1] === index)) { return setVboxSelected( { storeSelect: storeSelect.filter(vs => !(vs[0] === group && vs[1] === index)), stashSelect } ); } if (!storeSelect.length && !stashSelect.length) { return setVboxSelected({ storeSelect: [[group, index]], stashSelect }); } if (notValidCombo) { return setVboxSelected({ storeSelect: [[group, index]], stashSelect: [] }); } return setVboxSelected({ storeSelect: [...storeSelect, [group, index]], stashSelect }); } const classes = selected ? `${v.toLowerCase()} highlight` : `${v.toLowerCase()} ${notValidCombo ? 'fade' : ''}`; const vboxObject = shapes[v] ? shapes[v]() : v; const disabled = vbox.bits <= group; return ( ); } return (