import React, { Component } from "react"; import PropTypes from "prop-types"; import CustomInput from "components/CustomInput.jsx"; import CustomErrors from "components/CustomMessages.jsx"; import { connect } from "react-redux"; import { closeOverlay2, openOverlay3, closeOverlay3 } from "actions/stationOverlay"; import io from "io"; @connect(state => ({ playlists: state.station.playlists, })) export default class EditPlaylist extends Component { constructor(props) { super(props); CustomInput.initialize(this); } addSongToPlaylistCallback = (songId) => { io.getSocket((socket) => { // Add song to the playlist socket.emit("playlists.addSongToPlaylist", songId, this.props.playlistId, res => { if (res.status === "success") { this.messages.clearAddSuccess("Successfully added song."); } else { this.messages.addError(res.message); } this.props.dispatch(closeOverlay3()); }); }); }; addSongToPlaylist = () => { this.props.dispatch(openOverlay3("searchYouTube", this.addSongToPlaylistCallback)); }; changeDisplayName = () => { this.messages.clearErrorSuccess(); if (CustomInput.hasInvalidInput(this.input, ["displayName"])) { this.messages.clearAddError(this.props.t("general:someFieldsAreIncorrectError")); } else { io.getSocket(socket => { socket.emit("playlists.updateDisplayName", this.props.playlistId, this.input.displayName.getValue(), res => { if (res.status === "success") { this.messages.clearAddSuccess("Successfully changed name."); } else { this.messages.addError(res.message); } }); }); } }; deletePlaylist = () => { this.messages.clearErrorSuccess(); io.getSocket(socket => { socket.emit("playlists.remove", this.props.playlistId, res => { if (res.status === "success") { this.messages.clearAddSuccess("Successfully deleted playlist."); this.props.dispatch(closeOverlay2()); } else { this.messages.addError(res.message); } }); }); }; deleteSong = (songId) => { this.messages.clearErrorSuccess(); io.getSocket(socket => { socket.emit('playlists.removeSongFromPlaylist', songId, this.props.playlistId, res => { if (res.status === "success") { this.messages.clearAddSuccess("Successfully removed song."); } else { this.messages.addError(res.message); } }); }); }; promoteSong = (songId) => { this.messages.clearErrorSuccess(); io.getSocket(socket => { socket.emit('playlists.moveSongToTop', this.props.playlistId, songId, res => { if (res.status === "success") { this.messages.clearAddSuccess("Successfully moved song up."); } else { this.messages.addError(res.message); } }); }); }; demoteSong = (songId) => { this.messages.clearErrorSuccess(); io.getSocket(socket => { socket.emit('playlists.moveSongToBottom', this.props.playlistId, songId, res => { if (res.status === "success") { this.messages.clearAddSuccess("Successfully moved song up."); } else { this.messages.addError(res.message); } }); }); }; close = () => { this.props.dispatch(closeOverlay2()); }; render() { const { playlistId } = this.props; const playlist = this.props.playlists.find((playlist) => { return playlist.get("playlistId") === playlistId; }); if (!playlist) return null; return (

Edit Playlist

(this.input.displayName = ref) } original={ playlist.get("displayName") }/> { } (this.messages = ref) } />
); } }