Converting to base64
This commit is contained in:
@ -3062,7 +3062,7 @@ function createPlaylist(name, description, is_public, is_collaborative) {
|
||||
};
|
||||
}
|
||||
|
||||
function savePlaylist(uri, name, description, is_public, is_collaborative) {
|
||||
function savePlaylist(uri, name, description, is_public, is_collaborative, image) {
|
||||
return function (dispatch, getState) {
|
||||
|
||||
var data = {
|
||||
@ -3070,20 +3070,42 @@ function savePlaylist(uri, name, description, is_public, is_collaborative) {
|
||||
description: description,
|
||||
public: is_public,
|
||||
collaborative: is_collaborative
|
||||
};
|
||||
|
||||
sendRequest(dispatch, getState, 'users/' + getState().spotify.me.id + '/playlists/' + helpers.getFromUri('playlistid', uri), 'PUT', data).then(function (response) {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: uri,
|
||||
playlist: {
|
||||
name: name,
|
||||
public: is_public,
|
||||
collaborative: is_collaborative,
|
||||
description: description
|
||||
}
|
||||
});
|
||||
// Update the playlist fields
|
||||
};sendRequest(dispatch, getState, 'users/' + getState().spotify.me.id + '/playlists/' + helpers.getFromUri('playlistid', uri), 'PUT', data).then(function (response) {
|
||||
dispatch(uiActions.createNotification({ content: 'Saved' }));
|
||||
|
||||
// Save the image
|
||||
if (image) {
|
||||
sendRequest(dispatch, getState, 'users/' + getState().spotify.me.id + '/playlists/' + helpers.getFromUri('playlistid', uri) + '/image', 'PUT', image).then(function (response) {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: uri,
|
||||
playlist: {
|
||||
name: name,
|
||||
public: is_public,
|
||||
collaborative: is_collaborative,
|
||||
description: description,
|
||||
image: image
|
||||
}
|
||||
});
|
||||
}, function (error) {
|
||||
dispatch(coreActions.handleException('Could not save image', error));
|
||||
});
|
||||
|
||||
// No image, so we're done here
|
||||
} else {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: uri,
|
||||
playlist: {
|
||||
name: name,
|
||||
public: is_public,
|
||||
collaborative: is_collaborative,
|
||||
description: description
|
||||
}
|
||||
});
|
||||
}
|
||||
}, function (error) {
|
||||
dispatch(coreActions.handleException('Could not save playlist', error));
|
||||
});
|
||||
@ -4719,6 +4741,7 @@ function savePlaylist(uri, name) {
|
||||
var description = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
||||
var is_public = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
||||
var is_collaborative = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
||||
var image = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
|
||||
|
||||
switch (helpers.uriSource(uri)) {
|
||||
|
||||
@ -4728,6 +4751,7 @@ function savePlaylist(uri, name) {
|
||||
key: uri,
|
||||
name: name,
|
||||
description: description == '' ? null : description,
|
||||
image: image,
|
||||
is_public: is_public,
|
||||
is_collaborative: is_collaborative
|
||||
};
|
||||
@ -59263,7 +59287,7 @@ var SpotifyMiddleware = function () {
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_SAVE_PLAYLIST':
|
||||
store.dispatch(spotifyActions.savePlaylist(action.key, action.name, action.description, action.is_public, action.is_collaborative));
|
||||
store.dispatch(spotifyActions.savePlaylist(action.key, action.name, action.description, action.is_public, action.is_collaborative, action.image));
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_NEW_RELEASES_LOADED':
|
||||
@ -63873,6 +63897,7 @@ var EditPlaylistModal = function (_React$Component) {
|
||||
name: _this.props.data.name,
|
||||
description: _this.props.data.description ? _this.props.data.description : '',
|
||||
public: _this.props.data.public,
|
||||
image: null,
|
||||
collaborative: _this.props.data.collaborative
|
||||
};
|
||||
return _this;
|
||||
@ -63887,11 +63912,23 @@ var EditPlaylistModal = function (_React$Component) {
|
||||
this.setState({ error: 'Name is required' });
|
||||
return false;
|
||||
} else {
|
||||
this.props.coreActions.savePlaylist(this.props.data.uri, this.state.name, this.state.description, this.state.public, this.state.collaborative);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'setImage',
|
||||
value: function 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]);
|
||||
}
|
||||
}, {
|
||||
key: 'renderFields',
|
||||
value: function renderFields() {
|
||||
@ -63919,7 +63956,8 @@ var EditPlaylistModal = function (_React$Component) {
|
||||
onChange: function onChange(e) {
|
||||
return _this2.setState({ name: e.target.value });
|
||||
},
|
||||
value: this.state.name })
|
||||
value: this.state.name
|
||||
})
|
||||
)
|
||||
),
|
||||
_react2.default.createElement(
|
||||
@ -63938,7 +63976,27 @@ var EditPlaylistModal = function (_React$Component) {
|
||||
onChange: function onChange(e) {
|
||||
return _this2.setState({ description: e.target.value });
|
||||
},
|
||||
value: this.state.description })
|
||||
value: this.state.description
|
||||
})
|
||||
)
|
||||
),
|
||||
_react2.default.createElement(
|
||||
'div',
|
||||
{ className: 'field text' },
|
||||
_react2.default.createElement(
|
||||
'div',
|
||||
{ className: 'name' },
|
||||
'Cover image'
|
||||
),
|
||||
_react2.default.createElement(
|
||||
'div',
|
||||
{ className: 'input' },
|
||||
_react2.default.createElement('input', {
|
||||
type: 'file',
|
||||
onChange: function onChange(e) {
|
||||
return _this2.setImage(e);
|
||||
}
|
||||
})
|
||||
)
|
||||
),
|
||||
_react2.default.createElement(
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -13,6 +13,7 @@ export default class EditPlaylistModal extends React.Component{
|
||||
name: this.props.data.name,
|
||||
description: (this.props.data.description ? this.props.data.description : ''),
|
||||
public: this.props.data.public,
|
||||
image: null,
|
||||
collaborative: this.props.data.collaborative
|
||||
}
|
||||
}
|
||||
@ -24,12 +25,23 @@ export default class EditPlaylistModal extends React.Component{
|
||||
this.setState({error: 'Name is required'})
|
||||
return false
|
||||
} else {
|
||||
this.props.coreActions.savePlaylist(this.props.data.uri, this.state.name, this.state.description, this.state.public, this.state.collaborative)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
renderFields(){
|
||||
switch (helpers.uriSource(this.props.data.uri)){
|
||||
|
||||
@ -42,7 +54,8 @@ export default class EditPlaylistModal extends React.Component{
|
||||
<input
|
||||
type="text"
|
||||
onChange={ e => this.setState({ name: e.target.value })}
|
||||
value={ this.state.name } />
|
||||
value={ this.state.name }
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field text">
|
||||
@ -51,7 +64,17 @@ export default class EditPlaylistModal extends React.Component{
|
||||
<input
|
||||
type="text"
|
||||
onChange={ e => this.setState({ description: e.target.value })}
|
||||
value={ this.state.description } />
|
||||
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)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field checkbox white">
|
||||
|
||||
@ -831,5 +831,3 @@ export let getIndexedRecords = function(index, uris){
|
||||
export let titleCase = function(string){
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -110,7 +110,7 @@ export function reorderPlaylistTracks(uri, indexes, insert_before, snapshot_id =
|
||||
}
|
||||
}
|
||||
|
||||
export function savePlaylist(uri, name, description = '', is_public = false, is_collaborative = false){
|
||||
export function savePlaylist(uri, name, description = '', is_public = false, is_collaborative = false, image = null){
|
||||
switch (helpers.uriSource(uri)){
|
||||
|
||||
case 'spotify':
|
||||
@ -119,6 +119,7 @@ export function savePlaylist(uri, name, description = '', is_public = false, is_
|
||||
key: uri,
|
||||
name: name,
|
||||
description: (description == '' ? null : description),
|
||||
image: image,
|
||||
is_public: is_public,
|
||||
is_collaborative: is_collaborative
|
||||
}
|
||||
|
||||
@ -1488,7 +1488,7 @@ export function createPlaylist(name, description, is_public, is_collaborative){
|
||||
}
|
||||
}
|
||||
|
||||
export function savePlaylist(uri, name, description, is_public, is_collaborative){
|
||||
export function savePlaylist(uri, name, description, is_public, is_collaborative, image){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
var data = {
|
||||
@ -1498,20 +1498,51 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
|
||||
collaborative: is_collaborative
|
||||
}
|
||||
|
||||
sendRequest(dispatch, getState, 'users/'+ getState().spotify.me.id +'/playlists/'+ helpers.getFromUri('playlistid',uri), 'PUT', data)
|
||||
// Update the playlist fields
|
||||
sendRequest(
|
||||
dispatch, getState, 'users/'+ getState().spotify.me.id +'/playlists/'+ helpers.getFromUri('playlistid',uri), 'PUT', data)
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: uri,
|
||||
playlist: {
|
||||
name: name,
|
||||
public: is_public,
|
||||
collaborative: is_collaborative,
|
||||
description: description
|
||||
}
|
||||
})
|
||||
dispatch(uiActions.createNotification({content: 'Saved'}));
|
||||
|
||||
// Save the image
|
||||
if (image){
|
||||
sendRequest(dispatch, getState, 'users/'+ getState().spotify.me.id +'/playlists/'+ helpers.getFromUri('playlistid',uri)+'/image', 'PUT', image)
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: uri,
|
||||
playlist: {
|
||||
name: name,
|
||||
public: is_public,
|
||||
collaborative: is_collaborative,
|
||||
description: description,
|
||||
image: image
|
||||
}
|
||||
});
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not save image',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
|
||||
// No image, so we're done here
|
||||
} else {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: uri,
|
||||
playlist: {
|
||||
name: name,
|
||||
public: is_public,
|
||||
collaborative: is_collaborative,
|
||||
description: description
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
@ -1519,7 +1550,7 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
|
||||
error
|
||||
));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -92,14 +92,12 @@ const SpotifyMiddleware = (function(){
|
||||
store.dispatch(spotifyActions.addTracksToPlaylist(action.key, action.tracks_uris ))
|
||||
break;
|
||||
|
||||
|
||||
case 'SPOTIFY_REORDER_PLAYLIST_TRACKS':
|
||||
store.dispatch(spotifyActions.reorderPlaylistTracks(action.key, action.range_start, action.range_length, action.insert_before, action.snapshot_id ))
|
||||
break;
|
||||
|
||||
|
||||
case 'SPOTIFY_SAVE_PLAYLIST':
|
||||
store.dispatch(spotifyActions.savePlaylist(action.key, action.name, action.description, action.is_public, action.is_collaborative ))
|
||||
store.dispatch(spotifyActions.savePlaylist(action.key, action.name, action.description, action.is_public, action.is_collaborative, action.image))
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_NEW_RELEASES_LOADED':
|
||||
|
||||
Reference in New Issue
Block a user