import React, { Component } from "react"; const axios = require('axios'); class PlaylistView extends Component{ constructor(props){ super(props); console.log(this.props.match.params.name); this.state = { name: this.props.match.params.name, parts: [], error: false, error_text: null, add_part_value: '' } this.handleAddPart = this.handleAddPart.bind(this); this.handleAddPartChange = this.handleAddPartChange.bind(this); } componentDidMount(){ this.getPlaylistInfo(); } getPlaylistInfo(){ axios.get(`/api/playlist?name=${ this.state.name }`) .then((response) => { this.setState(response.data); }).catch((error) => { this.setState({ error: true, error_text: "error pulling playlist info" }); }); } handleAddPartChange(event){ this.setState({ add_part_value: event.target.value }); } handleAddPart(event){ var parts = this.state.parts; parts.push(this.state.add_part_value); this.setState({ parts: parts }); axios.post('/api/playlist', { name: this.state.name, parts: parts }).then((response) => { console.log(reponse); }).catch((error) => { console.log(error); }); } render(){ const table = ( { this.state.parts.map((part) => ) }

{ this.state.name }

); const error =

{ this.state.error_text }

; return this.state.error ? error : table; } } function Row (props) { return ( { props.part } remove ); } export default PlaylistView;