index.jsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. closeOverlay1: bindActionCreators(closeOverlay1, dispatch),
  35. closeOverlay2: bindActionCreators(closeOverlay2, dispatch),
  36. openOverlay2: bindActionCreators(openOverlay2, dispatch),
  37. }))
  38. export default class QueueList extends Component {
  39. constructor(props) {
  40. super(props);
  41. }
  42. addSongToQueueCallback = (songId) => {
  43. io.getSocket((socket) => {
  44. // Add song to queue
  45. console.log(this.props.station.stationId);
  46. socket.emit("stations.addToQueue", this.props.station.stationId, songId, res => {
  47. if (res.status === "success") {
  48. this.messages.clearAddSuccess("Successfully added song.");
  49. } else {
  50. this.messages.addError(res.message);
  51. }
  52. this.props.closeOverlay2();
  53. });
  54. });
  55. };
  56. addSongToQueue = () => {
  57. this.props.openOverlay2("searchYouTube", null, this.addSongToQueueCallback);
  58. };
  59. deselectAll = () => {
  60. this.props.onDeselectPlaylistQueue();
  61. }
  62. close = () => {
  63. this.props.closeOverlay1();
  64. };
  65. render() {
  66. return (
  67. <div className="overlay">
  68. <button onClick={ this.close } className="back"><i className="material-icons">arrow_back</i></button>
  69. <div className="content">
  70. <h1>Queue</h1>
  71. <CustomErrors onRef={ ref => (this.messages = ref) } />
  72. <SongList/>
  73. <button onClick={ this.addSongToQueue }>Add song to queue</button>
  74. <hr/>
  75. <PlaylistList/>
  76. {
  77. (this.props.station.privatePlaylistQueue)
  78. ? <button onClick={ this.deselectAll }>Deselect all playlists</button>
  79. : null
  80. }
  81. </div>
  82. </div>
  83. );
  84. }
  85. }