import React, { Component } from "react"; import { BrowserRouter as Redirect } from "react-router-dom"; const axios = require('axios'); import showMessage from "../Toast.js" class NewPlaylist extends Component { constructor(props) { super(props); this.state = { name: '', type: 'normal' } this.handleInputChange = this.handleInputChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } handleInputChange(event){ this.setState({ [event.target.name]: event.target.value }); } handleSubmit(event){ axios.get('/api/playlists') .then((response) => { var sameName = response.data.playlists.includes(this.state.name); if(sameName.length == false){ axios.put('/api/playlist', { name: this.state.name, parts: [], playlist_references: [], shuffle: false, type: this.state.type, }).then((response) => { showMessage(`${this.state.name} created`); }).catch((error) => { showMessage(`error creating playlist (${error.response.status})`); }); }else{ showMessage('named playlist already exists'); } }) .catch((error) => { showMessage(`error getting playlists (${error.response.status})`); }); } render(){ return (

new playlist

); } } export default NewPlaylist;