import { h, Component } from 'preact';
import PropTypes from 'prop-types';
import { articlePropTypes } from '../../common-prop-types';
export class SaveButton extends Component {
constructor(props) {
super(props);
const { isBookmarked } = props;
this.state = {
buttonText: isBookmarked ? 'Saved' : 'Save',
};
}
render() {
const { buttonText } = this.state;
const { article, isBookmarked, onClick, saveable = true } = this.props;
const mouseMove = (_e) => {
this.setState({ buttonText: isBookmarked ? 'Unsave' : 'Save' });
};
const mouseOut = (_e) => {
this.setState({ buttonText: isBookmarked ? 'Saved' : 'Save' });
};
const handleClick = (_e) => {
onClick(_e);
this.setState({
buttonText: isBookmarked ? 'Save' : 'Saved',
isBookmarked: !isBookmarked,
});
};
if (article.class_name === 'Article' && saveable) {
return (
);
}
if (article.class_name === 'User') {
return (
);
}
return null;
}
}
SaveButton.propTypes = {
article: articlePropTypes.isRequired,
isBookmarked: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired,
saveable: PropTypes.bool.isRequired,
};
SaveButton.displayName = 'SaveButton';