import React from 'react'; import Api from '../api'; import Rating from 'react-rating'; class FloxItem extends React.Component { constructor(props) { super(props); this.state = { removed: false, ratingColor: this.formatRating(), rating: this.props.data.rating } } render() { let title = this.props.data.title; return (
{this.props.released().year} {title} {this.props.logged ?
: ''} Watch Trailer {this.props.logged ? {this.state.removed ? "Bring it back" : "Remove from list"} : ''}
{this.props.image ? : }
{title} {this.state.rating + "/5 Rating"}
); } formatRating(rating = this.props.data.rating) { return rating.replace('.', '-'); } changeActiveKey() { this.props.changeActiveKey(this.props.id); } closeHiddenContent() { this.props.changeActiveKey(null); } handleItemRemove() { Api.handleItemRemove(this.props.id).done((value) => { this.setState({ removed: ! this.state.removed }) }).fail((value) => { if(value.status === 401) { alert('Unauthorized'); } else { alert('Server Error'); } }); } onHoverRate(value) { this.setState({ ratingColor: value ? this.formatRating(value.toString()) : this.formatRating(this.state.rating.toString()) }); } onChangeRate(rating) { Api.updateRating(this.props.id, rating).done((value) => { rating = rating.toString(); this.setState({ rating, ratingColor: this.formatRating(rating) }); }).fail((value) => { if(value.status === 401) { alert('Unauthorized'); } else { alert('Server Error'); } }); } } export default FloxItem;