import { h, Component } from 'preact'; import PropTypes from 'prop-types'; import { articlePropTypes } from '../../src/components/common-prop-types'; export class SaveButton extends Component { componentDidMount() { const { isBookmarked } = this.props; this.setState({ buttonText: isBookmarked ? 'SAVED' : 'SAVE' }); } render() { const { buttonText } = this.state; const { article, isBookmarked, onClick } = this.props; const mouseOut = _e => { this.setState({ buttonText: isBookmarked ? 'SAVED' : 'SAVE' }); }; const mouseOver = _e => { if (isBookmarked) { this.setState({ buttonText: 'UNSAVE' }); } }; if (article.class_name === 'Article') { return ( ); } if (article.class_name === 'User') { return ( ); } return null; } } SaveButton.propTypes = { article: articlePropTypes.isRequired, isBookmarked: PropTypes.bool.isRequired, onClick: PropTypes.func.isRequired, }; SaveButton.displayName = 'SaveButton';