2017-09-11 14:23:30 -04:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import {connect} from 'react-redux';
|
|
|
|
import paper from 'paper';
|
|
|
|
|
2017-09-22 12:12:07 -04:00
|
|
|
const SelectionHOC = function (WrappedComponent) {
|
2017-09-11 14:23:30 -04:00
|
|
|
class SelectionComponent extends React.Component {
|
|
|
|
componentDidMount () {
|
|
|
|
if (this.props.hoveredItem) {
|
|
|
|
paper.view.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
if (this.props.hoveredItem && this.props.hoveredItem !== prevProps.hoveredItem) {
|
|
|
|
// A hover item has been added. Update the view
|
2017-09-14 17:13:56 -04:00
|
|
|
if (prevProps.hoveredItem) {
|
|
|
|
prevProps.hoveredItem.remove();
|
|
|
|
}
|
2017-09-11 14:23:30 -04:00
|
|
|
} else if (!this.props.hoveredItem && prevProps.hoveredItem) {
|
|
|
|
// Remove the hover item
|
|
|
|
prevProps.hoveredItem.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
hoveredItem, // eslint-disable-line no-unused-vars
|
|
|
|
...props
|
|
|
|
} = this.props;
|
|
|
|
return (
|
|
|
|
<WrappedComponent {...props} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SelectionComponent.propTypes = {
|
|
|
|
hoveredItem: PropTypes.instanceOf(paper.Item)
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
hoveredItem: state.scratchPaint.hoveredItem
|
|
|
|
});
|
|
|
|
return connect(
|
|
|
|
mapStateToProps
|
|
|
|
)(SelectionComponent);
|
|
|
|
};
|
|
|
|
|
2017-09-22 12:12:07 -04:00
|
|
|
export default SelectionHOC;
|