2
0

PlaylistItem.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { connect } from "react-redux";
  4. import { openOverlay2 } from "actions/stationOverlay";
  5. import io from "io";
  6. @connect(state => ({
  7. user: {
  8. loggedIn: state.session.get("loggedIn"),
  9. userId: state.session.get("userId"),
  10. role: state.session.get("role"),
  11. },
  12. station: {
  13. stationId: state.station.info.get("stationId"),
  14. ownerId: state.station.info.get("ownerId"),
  15. mode: state.station.info.get("mode"),
  16. privatePlaylist: state.station.info.get("privatePlaylist"),
  17. },
  18. }))
  19. export default class PlaylistItem extends Component {
  20. constructor(props) {
  21. super(props);
  22. }
  23. isOwner = () => {
  24. if (this.props.user.loggedIn) {
  25. if (this.props.user.userId === this.props.station.ownerId) return true;
  26. }
  27. return false;
  28. };
  29. playPlaylist = (playlistId) => {
  30. //this.messages.clearErrorSuccess();
  31. io.getSocket((socket) => {
  32. socket.emit("stations.selectPrivatePlaylist", this.props.station.stationId, playlistId, (res) => {
  33. if (res.status === "success") {
  34. this.message.addSuccess("Successfully selected private playlist.");
  35. } else {
  36. this.messages.addError(res.message);
  37. }
  38. });
  39. });
  40. };
  41. getPlaylistAction = (playlistId) => {
  42. if (this.props.station.mode === "normal") {
  43. if (this.isOwner()) {
  44. const play = <span onClick={ () => { this.playPlaylist(playlistId) } }>PLAY!</span>;
  45. //const stop = <span onClick={ () => { this.stopPlaylist(playlistId) } }>STOP!</span>;
  46. const stop = null; // There's currently no backend functionality to stop a playlist from playing
  47. if (this.props.station.privatePlaylist === playlistId) return stop;
  48. else return play;
  49. }
  50. }
  51. return null;
  52. };
  53. render() {
  54. const { playlist } = this.props;
  55. return (
  56. <li>
  57. { playlist.get("displayName") } - <span onClick={ () => { this.props.dispatch(openOverlay2("editPlaylist", { playlistId: playlist.get("playlistId") })) } }>Edit</span>
  58. { this.getPlaylistAction(playlist.get("playlistId")) }
  59. </li>
  60. );
  61. }
  62. }