Files
Iris/src/js/components/Modal/EditPlaylistModal.js

98 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-11-14 17:32:36 +13:00
import React from 'react'
import Icon from '../Icon'
import * as helpers from '../../helpers'
export default class EditPlaylistModal extends React.Component{
constructor(props){
super(props)
this.state = {
error: null,
2016-11-14 17:32:36 +13:00
name: this.props.data.name,
description: (this.props.data.description ? this.props.data.description : ''),
2016-11-14 17:32:36 +13:00
is_public: this.props.data.is_public
}
}
savePlaylist(e){
e.preventDefault();
if (!this.state.name || this.state.name == ''){
this.setState({error: 'Name is required'})
return false
} else {
this.props.uiActions.savePlaylist(this.props.data.uri, this.state.name, this.state.is_public, this.state.description)
this.props.uiActions.closeModal()
return false
}
}
renderFields(){
switch (helpers.uriSource(this.props.data.uri)){
case 'spotify':
return (
<div>
<div className="field">
<input
type="text"
placeholder="Name"
onChange={ e => this.setState({ name: e.target.value })}
value={ this.state.name } />
</div>
<div className="field">
<input
type="text"
placeholder="Description"
onChange={ e => this.setState({ description: e.target.value })}
value={ this.state.description } />
</div>
<div className="field checkbox white">
<label>
<input
type="checkbox"
name="playlist_private"
checked={ this.state.is_public }
onChange={ e => this.setState({ is_public: !this.state.is_public })} />
<span className="label">Public</span>
</label>
</div>
</div>
)
break
default:
return (
<div>
<div className="field">
<input
type="text"
placeholder="Name"
onChange={ e => this.setState({ name: e.target.value })}
value={ this.state.name } />
</div>
</div>
)
}
2016-11-14 17:32:36 +13:00
}
render(){
return (
<div>
2017-06-21 09:16:26 +12:00
<h1>Edit playlist</h1>
{this.state.error ? <h3 className="red-text">{this.state.error}</h3> : null}
2016-11-14 17:32:36 +13:00
<form onSubmit={(e) => this.savePlaylist(e)}>
{this.renderFields()}
2017-02-05 19:57:29 +13:00
<div className="actions centered-text">
<button type="submit" className="primary wide">Save</button>
2017-02-05 19:57:29 +13:00
</div>
2016-11-14 17:32:36 +13:00
</form>
</div>
)
}
}