Adding POC lastfm authorization button

This commit is contained in:
James Barnsley
2017-11-02 21:20:56 +13:00
parent 5abb9c775a
commit 35a61686b3
13 changed files with 847 additions and 270 deletions

View File

@ -45,6 +45,28 @@ const sendRequest = (dispatch, getState, params ) => {
})
}
export function set(data){
return {
type: 'LASTFM_SET',
data: data
}
}
/**
* Handle authorization process
**/
export function authorizationGranted(data){
data.token_expiry = new Date().getTime() + data.expires_in;
return { type: 'LASTFM_AUTHORIZATION_GRANTED', data: data }
}
export function revokeAuthorization(){
return { type: 'LASTFM_AUTHORIZATION_REVOKED' }
}
export function connect(){
return (dispatch, getState) => {

View File

@ -9,6 +9,27 @@ export default function reducer(lastfm = {}, action){
case 'LASTFM_CONNECTED':
return Object.assign({}, lastfm, { connected: true, connecting: false });
case 'LASTFM_SET':
return Object.assign({}, lastfm, action.data)
case 'LASTFM_AUTHORIZATION_GRANTED':
return Object.assign({}, lastfm, {
enabled: true,
authorizing: false,
authorization: action.data,
api_key: action.data.api_key,
token_expiry: action.data.token_expiry
})
case 'LASTFM_AUTHORIZATION_REVOKED':
return Object.assign({}, lastfm, {
authorizing: false,
authorization: false,
api_key: false,
token_expiry: 0,
me: false
})
default:
return lastfm
}

View File

@ -5,6 +5,7 @@ var helpers = require('../../helpers.js')
var coreActions = require('../core/actions.js')
var uiActions = require('../ui/actions.js')
var pusherActions = require('./actions.js')
var lastfmActions = require('../lastfm/actions.js')
var spotifyActions = require('../spotify/actions.js')
const PusherMiddleware = (function(){
@ -431,7 +432,10 @@ const PusherMiddleware = (function(){
store.dispatch(spotifyActions.set({
locale: (action.config.locale ? action.config.locale : null),
country: (action.config.country ? action.config.country : null),
authorization_url: (action.config.authorization_url ? action.config.authorization_url : null)
authorization_url: (action.config.spotify_authorization_url ? action.config.spotify_authorization_url : null)
}))
store.dispatch(lastfmActions.set({
authorization_url: (action.config.lastfm_authorization_url ? action.config.lastfm_authorization_url : null)
}))
next(action )