SongItem.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { formatTime } from "utils";
  4. import { connect } from "react-redux";
  5. import io from "io";
  6. @connect(state => ({
  7. station: {
  8. stationId: state.station.info.get("id"),
  9. owner: state.station.info.get("ownerId"),
  10. },
  11. }))
  12. export default class SongItem extends Component {
  13. constructor(props) {
  14. super(props);
  15. }
  16. deleteSong = (songId) => {
  17. io.getSocket((socket) => {
  18. socket.emit("stations.removeFromQueue", this.props.station.stationId, songId, (data) => {
  19. if (data.status === "success") this.messages.clearAddSuccess("Successfully removed song.");
  20. else this.messages.clearAddError("Failed to remove song.", data.message);
  21. });
  22. });
  23. };
  24. isOwner = () => {
  25. if (this.props.loggedIn) {
  26. if (this.props.user.role === "admin") return true;
  27. if (this.props.user.userId === this.props.station.owner) return true;
  28. }
  29. return false;
  30. };
  31. render() {
  32. const { song } = this.props;
  33. const showRequestedBy = (song.get("requestedByUsername") && song.get("requestedByUsername") !== "Unknown");
  34. const showDelete = (this.isOwner());
  35. return (
  36. <li>
  37. <div className="left">
  38. <img src={ song.get("thumbnail") } onError={function(e) {e.target.src="/assets/images/notes.png"}}/>
  39. </div>
  40. <div className="right">
  41. <span className="duration">{ formatTime(song.get("duration")) }</span>
  42. <p className="title">{ song.get("title") }</p>
  43. <span className="title-artists-spacing"/>
  44. <p className="artists">{ song.get("artists").join(", ") }</p>
  45. {
  46. (showRequestedBy) ?
  47. <span>
  48. <span>Requested by: </span>
  49. <a href={`/u/${ song.get("requestedByUsername") }`}>{ song.get("requestedByUsername") }</a>
  50. </span> : null
  51. }
  52. {
  53. (showDelete)
  54. ? <i onClick={ () => { this.deleteSong(song.get("songId")) } }>Delete</i>
  55. : null
  56. }
  57. </div>
  58. </li>
  59. );
  60. }
  61. }