index.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 PlaylistList from "./PlaylistList.jsx";
  6. import { connect } from "react-redux";
  7. import { closeOverlay1, openOverlay2 } from "actions/stationOverlay";
  8. import io from "io";
  9. @connect(state => ({
  10. }))
  11. export default class Playlists extends Component {
  12. constructor(props) {
  13. super(props);
  14. CustomInput.initialize(this);
  15. }
  16. close = () => {
  17. this.props.dispatch(closeOverlay1());
  18. };
  19. createPlaylist = () => {
  20. this.messages.clearErrorSuccess();
  21. if (CustomInput.hasInvalidInput(this.input, ["description"])) {
  22. this.messages.clearAddError(this.props.t("general:someFieldsAreIncorrectError"));
  23. } else {
  24. io.getSocket(socket => {
  25. socket.emit('playlists.create', { displayName: this.input.description.getValue(), songs: [] }, res => {
  26. if (res.status === "success") {
  27. this.props.dispatch(openOverlay2("editPlaylist", { playlistId: res.playlistId }));
  28. } else {
  29. this.messages.addError(res.message);
  30. }
  31. });
  32. });
  33. }
  34. };
  35. /*stopPlaylist = (playlistId) => {
  36. this.messages.clearErrorSuccess();
  37. io.getSocket((socket) => {
  38. socket.emit("stations.selectPrivatePlaylist", this.props.stationId, playlistId, (res) => {
  39. if (res.status === "success") {
  40. this.message.addSuccess("Successfully selected private playlist.");
  41. } else {
  42. this.messages.addError(res.message);
  43. }
  44. });
  45. });
  46. };*/
  47. render() {
  48. return (
  49. <div className="overlay">
  50. <button onClick={ this.close }>Back</button>
  51. <h1>Playlists</h1>
  52. <CustomErrors onRef={ ref => (this.messages = ref) } />
  53. <CustomInput key="description" type="playlistDescription" name="description" label="Description" placeholder="Description" original={ this.props.description } onRef={ ref => (this.input.description = ref) } />
  54. <button onClick={ this.createPlaylist }>Create playlist</button>
  55. <h2>Playlists</h2>
  56. <PlaylistList/>
  57. </div>
  58. );
  59. }
  60. }