2016-11-14 17:32:36 +13:00
|
|
|
|
2018-02-01 08:06:40 +13:00
|
|
|
import React from 'react';
|
2016-11-14 17:32:36 +13:00
|
|
|
|
2018-02-01 08:06:40 +13:00
|
|
|
import Icon from '../Icon';
|
|
|
|
|
import * as helpers from '../../helpers';
|
2016-11-14 17:32:36 +13:00
|
|
|
|
|
|
|
|
export default class EditPlaylistModal extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props){
|
|
|
|
|
super(props)
|
|
|
|
|
this.state = {
|
2017-07-13 07:53:00 +12:00
|
|
|
error: null,
|
2016-11-14 17:32:36 +13:00
|
|
|
name: this.props.data.name,
|
2017-07-13 07:53:00 +12:00
|
|
|
description: (this.props.data.description ? this.props.data.description : ''),
|
2017-08-17 17:37:53 +12:00
|
|
|
public: this.props.data.public,
|
2018-07-06 16:57:56 +12:00
|
|
|
image: null,
|
2017-08-17 17:37:53 +12:00
|
|
|
collaborative: this.props.data.collaborative
|
2016-11-14 17:32:36 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 16:57:56 +12:00
|
|
|
savePlaylist(e){
|
2016-11-14 17:32:36 +13:00
|
|
|
e.preventDefault();
|
2017-07-13 07:53:00 +12:00
|
|
|
|
|
|
|
|
if (!this.state.name || this.state.name == ''){
|
|
|
|
|
this.setState({error: 'Name is required'})
|
|
|
|
|
return false
|
|
|
|
|
} else {
|
2018-07-06 16:57:56 +12:00
|
|
|
this.props.coreActions.savePlaylist(this.props.data.uri, this.state.name, this.state.description, this.state.public, this.state.collaborative, this.state.image)
|
2017-07-13 07:53:00 +12:00
|
|
|
this.props.uiActions.closeModal()
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 16:57:56 +12:00
|
|
|
setImage(e){
|
|
|
|
|
var self = this;
|
|
|
|
|
var file_reader = new FileReader();
|
|
|
|
|
|
|
|
|
|
file_reader.addEventListener("load", function(e){
|
|
|
|
|
self.setState({image: e.target.result});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
file_reader.readAsDataURL(e.target.files[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 07:53:00 +12:00
|
|
|
renderFields(){
|
|
|
|
|
switch (helpers.uriSource(this.props.data.uri)){
|
|
|
|
|
|
|
|
|
|
case 'spotify':
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2017-07-13 15:26:30 +12:00
|
|
|
<div className="field text">
|
2018-06-06 16:54:09 +12:00
|
|
|
<div className="name">Name</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ name: e.target.value })}
|
2018-07-06 16:57:56 +12:00
|
|
|
value={ this.state.name }
|
|
|
|
|
/>
|
2018-06-06 16:54:09 +12:00
|
|
|
</div>
|
2017-07-13 07:53:00 +12:00
|
|
|
</div>
|
2017-07-13 15:26:30 +12:00
|
|
|
<div className="field text">
|
2018-06-06 16:54:09 +12:00
|
|
|
<div className="name">Description</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ description: e.target.value })}
|
2018-07-06 16:57:56 +12:00
|
|
|
value={ this.state.description }
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="field text">
|
|
|
|
|
<div className="name">Cover image</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<input
|
|
|
|
|
type="file"
|
|
|
|
|
onChange={e => this.setImage(e)}
|
|
|
|
|
/>
|
2018-06-06 16:54:09 +12:00
|
|
|
</div>
|
2017-07-13 07:53:00 +12:00
|
|
|
</div>
|
|
|
|
|
<div className="field checkbox white">
|
2018-06-06 16:54:09 +12:00
|
|
|
<div className="name">
|
2018-05-29 21:05:03 +12:00
|
|
|
Options
|
|
|
|
|
</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<label>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
name="playlist_private"
|
|
|
|
|
checked={ this.state.public }
|
|
|
|
|
onChange={ e => this.setState({ public: !this.state.public })} />
|
|
|
|
|
<span className="label">Public</span>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
name="collaborative"
|
|
|
|
|
checked={ this.state.collaborative }
|
|
|
|
|
onChange={ e => this.setState({ collaborative: !this.state.collaborative })} />
|
|
|
|
|
<span className="label">Collaborative</span>
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
2017-07-13 07:53:00 +12:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2017-08-11 21:59:14 +12:00
|
|
|
<div className="field text">
|
2018-06-06 16:54:09 +12:00
|
|
|
<div className="name">Name</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ name: e.target.value })}
|
|
|
|
|
value={ this.state.name } />
|
|
|
|
|
</div>
|
2017-07-13 07:53:00 +12:00
|
|
|
</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>
|
2017-07-13 07:53:00 +12:00
|
|
|
{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)}>
|
2017-07-13 07:53:00 +12:00
|
|
|
|
|
|
|
|
{this.renderFields()}
|
|
|
|
|
|
2017-02-05 19:57:29 +13:00
|
|
|
<div className="actions centered-text">
|
2018-02-01 08:06:40 +13:00
|
|
|
<button type="submit" className="primary large">Save</button>
|
2017-02-05 19:57:29 +13:00
|
|
|
</div>
|
2016-11-14 17:32:36 +13:00
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|