import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import io from "io"; @connect(state => ({ user: { loggedIn: state.session.get("loggedIn"), }, likes: state.station.currentSong.getIn(["ratings", "likes"]), dislikes: state.station.currentSong.getIn(["ratings", "dislikes"]), liked: state.station.currentSong.getIn(["ratings", "liked"]), disliked: state.station.currentSong.getIn(["ratings", "disliked"]), ratingsEnabled: state.station.currentSong.getIn(["ratings", "enabled"]), songId: state.station.currentSong.get("songId"), })) export default class Ratings extends Component { constructor(props) { super(props); } like = () => { io.getSocket(socket => { socket.emit("songs.like", this.props.songId, data => {/*TODO Handle error/success*/}); }); }; dislike = () => { io.getSocket(socket => { socket.emit("songs.dislike", this.props.songId, data => {/*TODO Handle error/success*/}); }); }; unlike = () => { io.getSocket(socket => { socket.emit("songs.unlike", this.props.songId, data => {/*TODO Handle error/success*/}); }); }; undislike = () => { io.getSocket(socket => { socket.emit("songs.undislike", this.props.songId, data => {/*TODO Handle error/success*/}); }); }; render() { if (!this.props.ratingsEnabled) return null; const likes = { this.props.likes }; const dislikes = { this.props.dislikes }; let likeButton = thumb_up; let dislikeButton = thumb_down; if (this.props.user.loggedIn) { if (this.props.liked) likeButton = thumb_up; else likeButton = thumb_up; if (this.props.disliked) dislikeButton = thumb_down; else dislikeButton = thumb_down; } return (