140 lines
4.1 KiB
JavaScript
Raw Normal View History

2017-12-02 16:10:18 +01:00
/**
*
* PluginCard
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import cn from 'classnames';
2017-12-12 17:49:06 +01:00
import { isEmpty, replace } from 'lodash';
2017-12-02 18:46:22 +01:00
import { FormattedMessage } from 'react-intl';
// Temporary picture
import Button from 'components/Button';
2017-12-12 14:30:24 +01:00
import InstallPluginPopup from 'components/InstallPluginPopup';
2017-12-12 17:49:06 +01:00
import StarsContainer from 'components/StarsContainer';
2017-12-02 16:10:18 +01:00
import styles from './styles.scss';
2017-12-02 18:46:22 +01:00
class PluginCard extends React.Component {
2017-12-11 19:04:27 +01:00
state = { isOpen: false, boostrapCol: 'col-lg-4' };
2017-12-02 18:46:22 +01:00
componentDidMount() {
this.shouldOpenModal(this.props);
2017-12-11 19:04:27 +01:00
window.addEventListener('resize', this.setBoostrapCol);
this.setBoostrapCol();
2017-12-02 18:46:22 +01:00
}
componentWillReceiveProps(nextProps) {
if (nextProps.history.location.hash !== this.props.history.location.hash) {
this.shouldOpenModal(nextProps);
}
}
2017-12-11 19:04:27 +01:00
componentWillUnmount() {
2017-12-12 14:30:24 +01:00
window.removeEventListener('resize', this.setBoostrapCol);
2017-12-11 19:04:27 +01:00
}
setBoostrapCol = () => {
let boostrapCol = 'col-lg-4';
if (window.innerWidth > 1680) {
boostrapCol = 'col-lg-3';
}
if (window.innerWidth > 2300) {
boostrapCol = 'col-lg-2';
}
this.setState({ boostrapCol });
}
2017-12-12 14:30:24 +01:00
handleClick = () => {
this.props.history.push({
pathname: this.props.history.location.pathname,
hash: `${this.props.plugin.id}::description`,
});
}
2017-12-02 18:46:22 +01:00
shouldOpenModal = (props) => {
this.setState({ isOpen: !isEmpty(props.history.location.hash) });
}
render() {
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 (
2017-12-12 14:30:24 +01:00
<div className={cn(this.state.boostrapCol, styles.pluginCard)} onClick={this.handleClick}>
2017-12-02 18:46:22 +01:00
<div className={styles.wrapper}>
<div className={styles.cardTitle}>
<div><i className={`fa fa-${this.props.plugin.icon}`} /></div>
<div>{this.props.plugin.name}</div>
</div>
<div className={styles.cardDescription}>
<FormattedMessage id={this.props.plugin.description} />
2017-12-11 20:19:22 +01:00
&nbsp;<FormattedMessage id="app.components.PluginCard.more-details" />
2017-12-02 18:46:22 +01:00
</div>
<div className={styles.cardScreenshot}>
2017-12-11 19:04:27 +01:00
2017-12-02 18:46:22 +01:00
</div>
<div className={styles.cardPrice}>
<div>
<i className={`fa fa-${this.props.plugin.isCompatible ? 'check' : 'times'}`} />
<FormattedMessage id={`app.components.PluginCard.compatible${this.props.plugin.id === 'support-us' ? 'Community' : ''}`} />
</div>
2017-12-11 19:04:27 +01:00
<div>{this.props.plugin.price !== 0 ? `${this.props.plugin.price}` : ''}</div>
2017-12-02 18:46:22 +01:00
</div>
<div className={styles.cardFooter}>
<div className={styles.ratings}>
2017-12-12 17:49:06 +01:00
<StarsContainer ratings={this.props.plugin.ratings} />
2017-12-02 18:46:22 +01:00
<div>
<span style={{ fontWeight: '600', color: '#333740' }}>{this.props.plugin.ratings}</span>
<span style={{ fontWeight: '500', color: '#666666' }}>/5</span>
</div>
</div>
<div>
<Button
className={cn(buttonClass, styles.button)}
label={buttonLabel}
/>
</div>
</div>
2017-12-02 16:10:18 +01:00
</div>
2017-12-12 14:30:24 +01:00
<InstallPluginPopup
history={this.props.history}
isOpen={!isEmpty(this.props.history.location.hash) && replace(this.props.history.location.hash.split('::')[0], '#', '') === this.props.plugin.id}
plugin={this.props.plugin}
/>
2017-12-02 16:10:18 +01:00
</div>
2017-12-02 18:46:22 +01:00
);
}
2017-12-02 16:10:18 +01:00
}
PluginCard.defaultProps = {
isAlreadyInstalled: false,
plugin: {
description: '',
id: '',
icon: '',
name: '',
price: 0,
ratings: 5,
},
showSupportUsButton: false,
};
PluginCard.propTypes = {
2017-12-02 18:46:22 +01:00
history: PropTypes.object.isRequired,
2017-12-02 16:10:18 +01:00
isAlreadyInstalled: PropTypes.bool,
plugin: PropTypes.object,
showSupportUsButton: PropTypes.bool,
};
export default PluginCard;