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

150 lines
4.0 KiB
JavaScript
Raw Normal View History

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 = {
error: null,
2016-11-14 17:32:36 +13:00
name: this.props.data.name,
description: (this.props.data.description ? this.props.data.description : ''),
public: this.props.data.public,
2018-07-06 16:57:56 +12:00
image: null,
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();
if (!this.state.name || this.state.name == ''){
this.setState({error: 'Name is required'})
return false
} else {
2018-07-08 20:20:51 +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);
this.props.uiActions.closeModal();
return false;
}
}
2018-07-06 16:57:56 +12:00
setImage(e){
2018-07-08 20:20:51 +12:00
var self = this;
// Create a file-reader to import the selected image as a base64 string
2018-07-06 16:57:56 +12:00
var file_reader = new FileReader();
// Once the image is loaded, convert the result
2018-07-06 16:57:56 +12:00
file_reader.addEventListener("load", function(e){
var image_base64 = e.target.result.replace('data:image/jpeg;base64,','');
self.setState({image: image_base64});
2018-07-06 16:57:56 +12:00
});
// This calls the filereader to load the file
2018-07-06 16:57:56 +12:00
file_reader.readAsDataURL(e.target.files[0]);
}
renderFields(){
switch (helpers.uriSource(this.props.data.uri)){
case 'spotify':
return (
<div>
<div className="field text">
<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 }
/>
</div>
</div>
<div className="field text">
<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>
2018-07-08 20:20:51 +12:00
<div className="field file">
2018-07-06 16:57:56 +12:00
<div className="name">Cover image</div>
<div className="input">
<input
type="file"
2018-07-08 20:20:51 +12:00
placeholder="Leave empty to keep existing image"
2018-07-06 16:57:56 +12:00
onChange={e => this.setImage(e)}
/>
2018-07-08 20:20:51 +12:00
<div className="description">
JPEG only, 256kB max. Leave empty to keep cover image unchanged.
2018-07-08 20:20:51 +12:00
</div>
</div>
</div>
<div className="field checkbox white">
<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>
</div>
</div>
)
break
default:
return (
<div>
2017-08-11 21:59:14 +12:00
<div className="field text">
<div className="name">Name</div>
<div className="input">
<input
type="text"
onChange={ e => this.setState({ name: e.target.value })}
value={ this.state.name } />
</div>
</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">
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>
)
}
}