2016-10-16 12:37:37 +13:00
|
|
|
|
2017-06-02 09:31:05 +12:00
|
|
|
import * as helpers from '../../helpers'
|
|
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
export default function reducer(spotify = {}, action){
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
|
2016-11-06 15:47:37 +13:00
|
|
|
case 'SPOTIFY_CONNECT':
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'SPOTIFY_CONNECTING':
|
2016-12-12 09:07:47 +13:00
|
|
|
return Object.assign({}, spotify, { connected: false, connecting: true })
|
2016-10-16 12:37:37 +13:00
|
|
|
|
2016-10-21 16:34:16 +13:00
|
|
|
case 'SPOTIFY_CONNECTED':
|
2016-12-12 09:07:47 +13:00
|
|
|
return Object.assign({}, spotify, { connected: true, connecting: false })
|
|
|
|
|
|
|
|
|
|
case 'SPOTIFY_DISCONNECTED':
|
|
|
|
|
return Object.assign({}, spotify, { connected: false, connecting: false })
|
2016-10-21 16:34:16 +13:00
|
|
|
|
2017-02-06 10:07:32 +13:00
|
|
|
case 'SPOTIFY_SET_CONFIG':
|
2017-08-04 22:01:50 +12:00
|
|
|
var spotify = Object.assign({},spotify,action.config)
|
|
|
|
|
|
|
|
|
|
let access = 'none'
|
2017-08-04 22:33:49 +12:00
|
|
|
if (spotify.authentication_provider == 'http_api' && spotify.authorization){
|
2017-08-04 22:01:50 +12:00
|
|
|
access = 'full'
|
|
|
|
|
} else if (spotify.authentication_provider == 'backend' && spotify.backend_username){
|
|
|
|
|
access = 'limited'
|
|
|
|
|
}
|
|
|
|
|
spotify.access = access
|
|
|
|
|
return spotify
|
2017-02-06 10:07:32 +13:00
|
|
|
|
2016-11-19 08:44:25 +13:00
|
|
|
case 'PUSHER_SPOTIFY_TOKEN':
|
2017-08-04 22:33:49 +12:00
|
|
|
if( spotify.authorization ) return spotify;
|
2016-10-18 16:53:33 +13:00
|
|
|
return Object.assign({}, spotify, {
|
|
|
|
|
authorizing: false,
|
2016-11-19 08:44:25 +13:00
|
|
|
authorization: false,
|
2016-10-21 16:34:16 +13:00
|
|
|
access_token: action.data.access_token,
|
|
|
|
|
token_expiry: action.data.token_expiry
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-11-19 08:44:25 +13:00
|
|
|
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
2016-10-29 22:40:02 +13:00
|
|
|
return Object.assign({}, spotify, {
|
2017-08-04 22:01:50 +12:00
|
|
|
access: (spotify.authentication_provider == 'http_api' ? 'full' : 'limited'),
|
2016-10-29 22:40:02 +13:00
|
|
|
authorizing: false,
|
2016-11-19 08:44:25 +13:00
|
|
|
authorization: action.data,
|
2016-10-29 22:40:02 +13:00
|
|
|
access_token: action.data.access_token,
|
2016-11-19 08:44:25 +13:00
|
|
|
refresh_token: action.data.refresh_token,
|
2016-10-29 22:40:02 +13:00
|
|
|
token_expiry: action.data.token_expiry
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-10-29 22:40:02 +13:00
|
|
|
|
2016-10-28 15:58:07 +13:00
|
|
|
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
2016-10-18 16:53:33 +13:00
|
|
|
return Object.assign({}, spotify, {
|
2017-08-04 22:01:50 +12:00
|
|
|
access: (spotify.authentication_provider == 'http_api' ? 'none' : 'limited'),
|
2016-10-18 16:53:33 +13:00
|
|
|
authorizing: false,
|
|
|
|
|
authorization: false,
|
2016-10-21 09:56:07 +13:00
|
|
|
access_token: false,
|
2016-11-19 08:44:25 +13:00
|
|
|
refresh_token: false,
|
|
|
|
|
token_expiry: 0,
|
2016-10-19 14:09:34 +13:00
|
|
|
me: false
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2017-04-15 05:43:29 +12:00
|
|
|
case 'SPOTIFY_IMPORT_AUTHORIZATION':
|
|
|
|
|
return Object.assign({}, spotify, {
|
2017-08-04 22:01:50 +12:00
|
|
|
authentication_provider: 'http_api',
|
|
|
|
|
access: 'full',
|
2017-04-15 05:43:29 +12:00
|
|
|
authorizing: false,
|
|
|
|
|
authorization: action.authorization,
|
|
|
|
|
access_token: action.authorization.access_token,
|
|
|
|
|
refresh_token: action.authorization.refresh_token,
|
|
|
|
|
token_expiry: action.authorization.token_expiry,
|
|
|
|
|
me: action.user
|
|
|
|
|
})
|
|
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
case 'SPOTIFY_TOKEN_REFRESHING':
|
2016-12-12 09:07:47 +13:00
|
|
|
return Object.assign({}, spotify, { refreshing_token: true })
|
2016-10-21 09:56:07 +13:00
|
|
|
|
|
|
|
|
case 'SPOTIFY_TOKEN_REFRESHED':
|
|
|
|
|
return Object.assign({}, spotify, {
|
2016-12-12 09:07:47 +13:00
|
|
|
connected: true,
|
2016-10-21 09:56:07 +13:00
|
|
|
refreshing_token: false,
|
2016-10-21 16:34:16 +13:00
|
|
|
access_token: action.data.access_token,
|
2016-11-30 09:32:46 +13:00
|
|
|
token_expiry: action.data.token_expiry,
|
2017-08-04 22:01:50 +12:00
|
|
|
access_token_provider: action.access_token_provider
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-10-21 09:56:07 +13:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'SPOTIFY_DISCONNECTED':
|
2016-12-12 09:07:47 +13:00
|
|
|
return Object.assign({}, spotify, { connected: false, connecting: false })
|
2016-10-16 12:37:37 +13:00
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
case 'SPOTIFY_ME_LOADED':
|
2016-12-12 09:07:47 +13:00
|
|
|
return Object.assign({}, spotify, { me: action.data })
|
2016-11-01 08:57:28 +13:00
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
2016-11-19 11:13:01 +13:00
|
|
|
if( !action.data ) return Object.assign({}, spotify)
|
2016-11-21 16:26:47 +13:00
|
|
|
var albums = []
|
|
|
|
|
for( var i = 0; i < action.data.items.length; i++ ){
|
|
|
|
|
albums.push( Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
action.data.items[i].album,
|
|
|
|
|
{
|
|
|
|
|
added_at: action.data.items[i].added_at
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
}
|
2016-11-19 11:13:01 +13:00
|
|
|
return Object.assign({}, spotify, {
|
2016-11-21 16:26:47 +13:00
|
|
|
library_albums: albums,
|
2016-11-19 11:13:01 +13:00
|
|
|
library_albums_more: action.data.next
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-10-20 21:38:01 +13:00
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED_MORE':
|
2016-11-21 16:26:47 +13:00
|
|
|
var albums = []
|
|
|
|
|
for( var i = 0; i < action.data.items.length; i++ ){
|
|
|
|
|
albums.push( Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
action.data.items[i].album,
|
|
|
|
|
{
|
|
|
|
|
added_at: action.data.items[i].added_at
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
}
|
2016-11-19 11:13:01 +13:00
|
|
|
return Object.assign({}, spotify, {
|
2016-11-21 16:26:47 +13:00
|
|
|
library_albums: [...spotify.library_albums, ...albums ],
|
2016-11-19 11:13:01 +13:00
|
|
|
library_albums_more: action.data.next
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-11-01 08:57:28 +13:00
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
2016-11-19 11:13:01 +13:00
|
|
|
if( !action.data ) return Object.assign({}, spotify)
|
|
|
|
|
var tracks = Object.assign([], action.data.items)
|
|
|
|
|
for( var i = 0; i < tracks.length; i++ ){
|
|
|
|
|
tracks[i] = Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
tracks[i].track,
|
|
|
|
|
{
|
|
|
|
|
added_at: tracks[i].added_at
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return Object.assign({}, spotify, {
|
|
|
|
|
library_tracks: tracks,
|
|
|
|
|
library_tracks_more: action.data.next
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-11-19 11:13:01 +13:00
|
|
|
|
|
|
|
|
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
|
|
|
|
var tracks = Object.assign([], action.data.items)
|
|
|
|
|
for( var i = 0; i < tracks.length; i++ ){
|
|
|
|
|
tracks[i] = Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
tracks[i].track,
|
|
|
|
|
{
|
|
|
|
|
added_at: tracks[i].added_at
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return Object.assign({}, spotify, {
|
2016-11-21 10:06:25 +13:00
|
|
|
library_tracks: [...spotify.library_tracks, ...tracks],
|
2016-11-19 11:13:01 +13:00
|
|
|
library_tracks_more: action.data.next
|
2016-12-12 09:07:47 +13:00
|
|
|
})
|
2016-10-26 16:55:47 +13:00
|
|
|
|
|
|
|
|
case 'SPOTIFY_FEATURED_PLAYLISTS_LOADED':
|
2016-12-12 09:07:47 +13:00
|
|
|
return Object.assign({}, spotify, { featured_playlists: action.data })
|
2016-10-26 16:55:47 +13:00
|
|
|
|
2016-10-27 10:02:12 +13:00
|
|
|
case 'SPOTIFY_NEW_RELEASES_LOADED':
|
|
|
|
|
return Object.assign({}, spotify, { new_releases: action.data });
|
|
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
case 'SPOTIFY_NEW_RELEASES_LOADED_MORE':
|
|
|
|
|
return Object.assign({}, spotify, { new_releases: {
|
|
|
|
|
href: action.data.albums.href,
|
|
|
|
|
next: action.data.albums.next,
|
|
|
|
|
previous: action.data.albums.previous,
|
|
|
|
|
items: [ ...spotify.new_releases.items, ...action.data.albums.items ]
|
2016-12-12 09:07:47 +13:00
|
|
|
}})
|
2016-11-01 08:57:28 +13:00
|
|
|
|
2017-01-11 13:52:55 +13:00
|
|
|
case 'SPOTIFY_DISCOVER_LOADED':
|
|
|
|
|
if( !action.data ) return Object.assign({}, spotify, { discover: [] })
|
|
|
|
|
return Object.assign({}, spotify, { discover: [...spotify.discover, ...[action.data]] })
|
|
|
|
|
|
2017-05-12 05:22:57 +12:00
|
|
|
case 'SPOTIFY_RECOMMENDATIONS_LOADED':
|
|
|
|
|
return Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
spotify,
|
|
|
|
|
{
|
2017-05-16 08:54:45 +12:00
|
|
|
recommendations: {
|
|
|
|
|
artists_uris: action.artists_uris,
|
|
|
|
|
albums_uris: action.albums_uris,
|
|
|
|
|
tracks: action.tracks
|
|
|
|
|
}
|
2017-05-12 05:22:57 +12:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
case 'SPOTIFY_FAVORITES_LOADED':
|
|
|
|
|
return Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
spotify,
|
|
|
|
|
{
|
2017-06-02 09:31:05 +12:00
|
|
|
favorite_artists: action.artists_uris,
|
|
|
|
|
favorite_tracks: action.tracks_uris
|
2017-05-12 05:22:57 +12:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
case 'SPOTIFY_AUTOCOMPLETE_LOADING':
|
|
|
|
|
var autocomplete_results = spotify.autocomplete_results
|
|
|
|
|
autocomplete_results[action.field_id] = {loading: true}
|
|
|
|
|
return Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
spotify,
|
|
|
|
|
{
|
|
|
|
|
autocomplete_results: autocomplete_results
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
case 'SPOTIFY_AUTOCOMPLETE_LOADED':
|
|
|
|
|
var autocomplete_results = spotify.autocomplete_results
|
|
|
|
|
autocomplete_results[action.field_id] = action.results
|
|
|
|
|
autocomplete_results[action.field_id].loading = false
|
|
|
|
|
return Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
spotify,
|
|
|
|
|
{
|
|
|
|
|
autocomplete_results: autocomplete_results
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
case 'SPOTIFY_AUTOCOMPLETE_CLEAR':
|
|
|
|
|
var autocomplete_results = spotify.autocomplete_results
|
|
|
|
|
if (typeof(autocomplete_results[action.field_id]) !== 'undefined'){
|
|
|
|
|
delete autocomplete_results[action.field_id]
|
|
|
|
|
}
|
|
|
|
|
return Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
spotify,
|
|
|
|
|
{
|
|
|
|
|
autocomplete_results: autocomplete_results
|
|
|
|
|
})
|
|
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
default:
|
|
|
|
|
return spotify
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|