all files / src/components/ FaveStar.jsx

70.59% Statements 12/17
100% Branches 0/0
0% Functions 0/3
68.75% Lines 11/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                          
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import TooltipWrapper from './TooltipWrapper';
import { t } from '../locales';
 
const propTypes = {
  itemId: PropTypes.number.isRequired,
  fetchFaveStar: PropTypes.func,
  saveFaveStar: PropTypes.func,
  isStarred: PropTypes.bool.isRequired,
};
 
export default class FaveStar extends React.Component {
  componentDidMount() {
    this.props.fetchFaveStar(this.props.itemId);
  }
 
  onClick(e) {
    e.preventDefault();
    this.props.saveFaveStar(this.props.itemId, this.props.isStarred);
  }
 
  render() {
    const iconClassNames = cx('fa', {
      'fa-star': this.props.isStarred,
      'fa-star-o': !this.props.isStarred,
    });
 
    return (
      <TooltipWrapper
        label="fave-unfave"
        tooltip={t('Click to favorite/unfavorite')}
      >
        <a
          href="#"
          onClick={this.onClick.bind(this)}
          className="fave-unfave-icon"
        >
          <i className={iconClassNames} />
        </a>
      </TooltipWrapper>
    );
  }
}
 
FaveStar.propTypes = propTypes;