import React, { Component } from "react"; const axios = require('axios'); class PlaylistView extends Component{ constructor(props){ super(props); this.state = { name: this.props.match.params.name, parts: [], type: null, error: false, error_text: null, day_boundary: '', newPlaylistName: '', shuffle: false } this.handleAddPart = this.handleAddPart.bind(this); this.handleInputChange = this.handleInputChange.bind(this); this.handleRemoveRow = this.handleRemoveRow.bind(this); this.handleRun = this.handleRun.bind(this); this.handleShuffleChange = this.handleShuffleChange.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" }); }); } handleInputChange(event){ this.setState({ [event.target.name]: event.target.value }); if(event.target.name == 'day_boundary'){ this.handleDayBoundaryChange(event.target.value); } } handleDayBoundaryChange(boundary) { axios.post('/api/playlist', { name: this.state.name, day_boundary: parseInt(boundary) }).catch((error) => { console.log(error); }); } handleShuffleChange(event) { this.setState({ shuffle: event.target.checked }); axios.post('/api/playlist', { name: this.state.name, shuffle: event.target.checked }).catch((error) => { console.log(error); }); } handleAddPart(event){ var parts = this.state.parts; parts.push(this.state.newPlaylistName); this.setState({ parts: parts, add_part_value: '' }); axios.post('/api/playlist', { name: this.state.name, parts: parts }).catch((error) => { console.log(error); }); } handleRemoveRow(id, event){ var parts = this.state.parts; parts = parts.filter(e => e !== id); this.setState({ parts: parts }); if(parts.length == 0) { parts = -1; } axios.post('/api/playlist', { name: this.state.name, parts: parts }).catch((error) => { console.log(error); }); } handleRun(event){ axios.get('/api/playlist/run', {params: {name: this.state.name}}) .catch((error) => { console.log(error); }); } render(){ const table = (
{ this.state.name } |
|
---|---|
shuffle output? | |
day boundary | |
{ this.state.error_text }
; return this.state.error ? error : table; } } function Row (props) { return (