/** * * PluginCard * */ import React from 'react'; import PropTypes from 'prop-types'; import cn from 'classnames'; import { isEmpty, map, times } from 'lodash'; import { FormattedMessage } from 'react-intl'; // Temporary picture import Button from 'components/Button'; import FakeScreenShot from './screenshot.png'; import styles from './styles.scss'; class PluginCard extends React.Component { state = { isOpen: false }; componentDidMount() { this.shouldOpenModal(this.props); } componentWillReceiveProps(nextProps) { if (nextProps.history.location.hash !== this.props.history.location.hash) { this.shouldOpenModal(nextProps); } } shouldOpenModal = (props) => { this.setState({ isOpen: !isEmpty(props.history.location.hash) }); } render() { const stars = Math.round(this.props.plugin.ratings); const coloredStars = times(stars, String); const emptyStars = times(5 - stars, String); const buttonClass = !this.props.isAlreadyInstalled || this.props.showSupportUsButton ? styles.primary : styles.secondary; let buttonLabel = this.props.isAlreadyInstalled ? 'app.components.PluginCard.Button.label.install' : 'app.components.PluginCard.Button.label.download'; if (this.props.showSupportUsButton) { buttonLabel = 'app.components.PluginCard.Button.label.support'; } return (
{this.props.plugin.name}
plugin screenshot
{this.props.plugin.price !== 0 ? `${this.props.plugin.price}€` : }
{map(coloredStars, star => )}
{map(emptyStars, s => )}
{this.props.plugin.ratings} /5
); } } PluginCard.defaultProps = { isAlreadyInstalled: false, plugin: { description: '', id: '', icon: '', name: '', price: 0, ratings: 5, }, showSupportUsButton: false, }; PluginCard.propTypes = { history: PropTypes.object.isRequired, isAlreadyInstalled: PropTypes.bool, plugin: PropTypes.object, showSupportUsButton: PropTypes.bool, }; export default PluginCard;