Refreshing token; Default albums view
This commit is contained in:
1
src/js/bootstrap.js
vendored
1
src/js/bootstrap.js
vendored
@ -61,7 +61,6 @@ var initialState = {
|
||||
track: {}
|
||||
},
|
||||
spotify: {
|
||||
enabled: true,
|
||||
connected: false,
|
||||
me: false,
|
||||
autocomplete_results: {},
|
||||
|
||||
@ -100,7 +100,7 @@ class SpotifyAuthenticationFrame extends React.Component{
|
||||
}
|
||||
}
|
||||
|
||||
renderAuthorizeButton(){
|
||||
render(){
|
||||
if (this.state.authorizing){
|
||||
return (
|
||||
<button className="working">
|
||||
@ -117,39 +117,13 @@ class SpotifyAuthenticationFrame extends React.Component{
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
renderRefreshButton(){
|
||||
if (!this.props.authorized) return null
|
||||
|
||||
if (this.props.refreshing_token){
|
||||
return (
|
||||
<button className="working">
|
||||
Force token refresh
|
||||
</button>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<button onClick={() => this.props.spotifyActions.refreshingToken()}>Force token refresh</button>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<span>
|
||||
{ this.renderAuthorizeButton() }
|
||||
{ this.renderRefreshButton() }
|
||||
</span>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
authorization_url: state.spotify.authorization_url,
|
||||
authorized: state.spotify.authorization,
|
||||
authorizing: state.spotify.authorizing,
|
||||
refreshing_token: state.spotify.refreshing_token
|
||||
authorizing: state.spotify.authorizing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,10 +22,7 @@ const CoreMiddleware = (function(){
|
||||
store.dispatch(mopidyActions.connect())
|
||||
store.dispatch(pusherActions.connect())
|
||||
store.dispatch(lastfmActions.connect())
|
||||
|
||||
if (store.getState().spotify.enabled){
|
||||
store.dispatch(spotifyActions.connect())
|
||||
}
|
||||
store.dispatch(spotifyActions.connect())
|
||||
|
||||
next(action)
|
||||
break
|
||||
|
||||
@ -149,15 +149,24 @@ function refreshToken( dispatch, getState ){
|
||||
})
|
||||
.then(
|
||||
response => {
|
||||
var token = response.spotify_token
|
||||
token.token_expiry = new Date().getTime() + ( token.expires_in * 1000 );
|
||||
token.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
access_token_provider: 'backend',
|
||||
data: token
|
||||
});
|
||||
resolve(token);
|
||||
if (response.type == 'error'){
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||
dispatch(uiActions.createNotification(response.message,'bad'))
|
||||
console.error('Could not refresh token', response)
|
||||
reject(response)
|
||||
|
||||
} else {
|
||||
var token = response.spotify_token
|
||||
token.token_expiry = new Date().getTime() + ( token.expires_in * 1000 );
|
||||
token.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
access_token_provider: 'backend',
|
||||
data: token
|
||||
});
|
||||
resolve(token);
|
||||
}
|
||||
|
||||
},
|
||||
error => {
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||
@ -943,7 +952,7 @@ export function playArtistTopTracks(uri){
|
||||
* ======================================================================================
|
||||
**/
|
||||
|
||||
export function getUser( uri ){
|
||||
export function getUser(uri){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
// get the user
|
||||
@ -956,8 +965,15 @@ export function getUser( uri ){
|
||||
});
|
||||
})
|
||||
|
||||
dispatch(getUserPlaylists(uri))
|
||||
}
|
||||
}
|
||||
|
||||
export function getUserPlaylists(user_uri){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
// get the first page of playlists
|
||||
sendRequest( dispatch, getState, 'users/'+ helpers.getFromUri('userid', uri) +'/playlists?limit=40' )
|
||||
sendRequest( dispatch, getState, 'users/'+ helpers.getFromUri('userid', user_uri) +'/playlists?limit=40' )
|
||||
.then( response => {
|
||||
|
||||
var playlists = []
|
||||
@ -979,7 +995,7 @@ export function getUser( uri ){
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_USER_PLAYLISTS_LOADED',
|
||||
key: uri,
|
||||
key: user_uri,
|
||||
data: response
|
||||
});
|
||||
})
|
||||
|
||||
@ -16,10 +16,6 @@ const SpotifyMiddleware = (function(){
|
||||
|
||||
switch(action.type){
|
||||
|
||||
case 'SPOTIFY_CONNECT':
|
||||
store.dispatch( spotifyActions.getMe() )
|
||||
break
|
||||
|
||||
case 'SPOTIFY_CONNECTED':
|
||||
var label = null
|
||||
if (store.getState().spotify.me) label = store.getState().spotify.me.id
|
||||
@ -31,6 +27,9 @@ const SpotifyMiddleware = (function(){
|
||||
store.dispatch(spotifyActions.getAllLibraryPlaylists())
|
||||
}
|
||||
|
||||
// Get the current logged-in user
|
||||
store.dispatch(spotifyActions.getMe())
|
||||
|
||||
next(action)
|
||||
break
|
||||
|
||||
@ -400,6 +399,13 @@ const SpotifyMiddleware = (function(){
|
||||
store.dispatch(pusherActions.setUsername(name))
|
||||
}
|
||||
ReactGA.event({ category: 'Spotify', action: 'Authorization verified', label: action.data.id })
|
||||
|
||||
store.dispatch({
|
||||
type: 'USER_LOADED',
|
||||
key: action.data.uri,
|
||||
user: action.data
|
||||
})
|
||||
|
||||
next(action)
|
||||
break;
|
||||
|
||||
|
||||
@ -156,7 +156,7 @@ class Settings extends React.Component {
|
||||
|
||||
renderServiceStatus(service){
|
||||
|
||||
let colour = 'grey'
|
||||
let colour = 'red'
|
||||
let icon = 'close'
|
||||
let name = service.charAt(0).toUpperCase() + service.slice(1).toLowerCase()
|
||||
let text = 'Disconnected'
|
||||
@ -165,12 +165,13 @@ class Settings extends React.Component {
|
||||
|
||||
if (service.connecting){
|
||||
icon = 'plug'
|
||||
colour = 'grey'
|
||||
text = 'Connecting'
|
||||
} else if (name == 'Spotify' && (!this.props.mopidy.uri_schemes || !this.props.mopidy.uri_schemes.includes('spotify:'))){
|
||||
icon = 'exclamation-triangle'
|
||||
colour = 'orange'
|
||||
text = 'Mopidy-Spotify not detected'
|
||||
} else if (name == 'Spotify' && !service.authorization){
|
||||
} else if (service.connected && name == 'Spotify' && !service.authorization){
|
||||
icon = 'lock'
|
||||
colour = 'orange'
|
||||
text = 'Limited access'
|
||||
@ -364,6 +365,7 @@ class Settings extends React.Component {
|
||||
<div className="name">Reset</div>
|
||||
<div className="input">
|
||||
<ConfirmationButton className="destructive" content="Reset all settings" confirmingContent="Are you sure?" onConfirm={() => this.resetAllSettings()} />
|
||||
<button onClick={e => this.props.spotifyActions.refreshingToken()}>Refresh Spotify token</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -27,11 +27,20 @@ class User extends React.Component{
|
||||
}
|
||||
|
||||
componentWillReceiveProps( nextProps ){
|
||||
if( nextProps.params.uri != this.props.params.uri ) this.loadUser( nextProps )
|
||||
if (nextProps.params.uri != this.props.params.uri ){
|
||||
this.loadUser( nextProps )
|
||||
}
|
||||
}
|
||||
|
||||
loadUser( props = this.props ){
|
||||
if (!props.user) this.props.spotifyActions.getUser( props.params.uri )
|
||||
if (!props.user){
|
||||
this.props.spotifyActions.getUser(props.params.uri)
|
||||
}
|
||||
|
||||
// We got a user, but we haven't fetched their playlists yet
|
||||
if (props.user && !props.user.playlists_uris){
|
||||
this.props.spotifyActions.getUserPlaylists(props.params.uri)
|
||||
}
|
||||
}
|
||||
|
||||
loadMore(){
|
||||
|
||||
@ -91,15 +91,7 @@ class LibraryAlbums extends React.Component{
|
||||
link_prefix={global.baseURL+"album/"} />
|
||||
</section>
|
||||
)
|
||||
}else if( this.props.view == 'thumbnails' ){
|
||||
return (
|
||||
<section className="content-wrapper">
|
||||
<AlbumGrid
|
||||
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
||||
albums={albums} />
|
||||
</section>
|
||||
)
|
||||
}else{
|
||||
}else if( this.props.view == 'detail' ){
|
||||
return (
|
||||
<section className="content-wrapper albums-detail-subview">
|
||||
{
|
||||
@ -124,6 +116,14 @@ class LibraryAlbums extends React.Component{
|
||||
}
|
||||
</section>
|
||||
)
|
||||
}else{
|
||||
return (
|
||||
<section className="content-wrapper">
|
||||
<AlbumGrid
|
||||
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
||||
albums={albums} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,14 +155,14 @@ class LibraryAlbums extends React.Component{
|
||||
}
|
||||
|
||||
var view_options = [
|
||||
{
|
||||
value: 'detail',
|
||||
label: 'Detail'
|
||||
},
|
||||
{
|
||||
value: 'thumbnails',
|
||||
label: 'Thumbnails'
|
||||
},
|
||||
{
|
||||
value: 'detail',
|
||||
label: 'Detail'
|
||||
},
|
||||
{
|
||||
value: 'list',
|
||||
label: 'List'
|
||||
|
||||
Reference in New Issue
Block a user