index.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import CustomInput from "components/CustomInput.jsx";
  4. import CustomErrors from "components/CustomMessages.jsx";
  5. import SongList from "./SongList.jsx";
  6. import PlaylistList from "./PlaylistList.jsx";
  7. import { connect } from "react-redux";
  8. import { closeOverlay1, openOverlay2, closeOverlay2 } from "actions/stationOverlay";
  9. import { selectPlaylist, deselectPlaylists } from "actions/playlistQueue";
  10. import io from "io";
  11. @connect(state => ({
  12. user: {
  13. loggedIn: state.session.get("loggedIn"),
  14. userId: state.session.get("userId"),
  15. role: state.session.get("role"),
  16. },
  17. station: {
  18. stationId: state.station.info.get("stationId"),
  19. owner: state.station.info.get("ownerId"),
  20. playlistSelectedId: state.station.info.get("playlistSelected"),
  21. songList: state.station.info.get("songList"),
  22. },
  23. song: {
  24. exists: state.station.currentSong.get("songId") !== "",
  25. title: state.station.currentSong.get("title"),
  26. artists: state.station.currentSong.get("artists"),
  27. duration: state.station.currentSong.getIn(["timings", "duration"]),
  28. thumbnail: state.station.currentSong.get("thumbnail"),
  29. },
  30. }))
  31. export default class QueueList extends Component {
  32. constructor(props) {
  33. super(props);
  34. }
  35. addSongToQueueCallback = (songId) => {
  36. io.getSocket((socket) => {
  37. // Add song to queue
  38. console.log(this.props.station.stationId);
  39. socket.emit("stations.addToQueue", this.props.station.stationId, songId, res => {
  40. if (res.status === "success") {
  41. this.messages.clearAddSuccess("Successfully added song.");
  42. } else {
  43. this.messages.addError(res.message);
  44. }
  45. this.props.dispatch(closeOverlay2());
  46. });
  47. });
  48. };
  49. addSongToQueue = () => {
  50. this.props.dispatch(openOverlay2("searchYouTube", null, this.addSongToQueueCallback));
  51. };
  52. deselectAll = () => {
  53. this.props.dispatch(deselectPlaylists());
  54. }
  55. close = () => {
  56. this.props.dispatch(closeOverlay1());
  57. };
  58. render() {
  59. return (
  60. <div className="overlay">
  61. <button onClick={ this.close } className="back"><i className="material-icons">arrow_back</i></button>
  62. <div className="content">
  63. <h1>Queue</h1>
  64. <CustomErrors onRef={ ref => (this.messages = ref) } />
  65. <SongList/>
  66. <button onClick={ this.addSongToQueue }>Add song to queue</button>
  67. <hr/>
  68. <PlaylistList/>
  69. {
  70. (this.props.station.playlistSelectedId)
  71. ? <button onClick={ this.deselectAll }>Deselect all playlists</button>
  72. : null
  73. }
  74. </div>
  75. </div>
  76. );
  77. }
  78. }