index.jsx 2.7 KB

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