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: [], playlist_references: [], type: null, error: false, error_text: null, day_boundary: '', newPlaylistName: '', newPlaylistReference: '', shuffle: false } this.handleAddPart = this.handleAddPart.bind(this); this.handleAddReference = this.handleAddReference.bind(this); this.handleInputChange = this.handleInputChange.bind(this); this.handleRemoveRow = this.handleRemoveRow.bind(this); this.handleRemoveRefRow = this.handleRemoveRefRow.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 check = this.state.parts.filter((e) => { return e == event.target.value; }); if(check.length == 0) { var parts = this.state.parts.slice(); parts.push(this.state.newPlaylistName); parts.sort(function(a, b){ if(a < b) { return -1; } if(a > b) { return 1; } return 0; }); this.setState({ parts: parts, newPlaylistName: '' }); axios.post('/api/playlist', { name: this.state.name, parts: parts }).catch((error) => { console.log(error); }); } } handleAddReference(event){ var check = this.state.playlist_references.filter((e) => { return e == event.target.value; }); if(check.length == 0) { var playlist_references = this.state.playlist_references.slice(); playlist_references.push(this.state.newPlaylistReference); playlist_references.sort(function(a, b){ if(a < b) { return -1; } if(a > b) { return 1; } return 0; }); this.setState({ playlist_references: playlist_references, newPlaylistReference: '' }); axios.post('/api/playlist', { name: this.state.name, playlist_references: playlist_references }).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); }); } handleRemoveRefRow(id, event){ var playlist_references = this.state.playlist_references; playlist_references = playlist_references.filter(e => e !== id); this.setState({ playlist_references: playlist_references }); if(playlist_references.length == 0) { playlist_references = -1; } axios.post('/api/playlist', { name: this.state.name, playlist_references: playlist_references }).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 ListBlock(props) { return (