Unifying loader syntaxes

This commit is contained in:
James Barnsley
2018-08-13 19:58:36 +12:00
parent e1fad661e5
commit abc08d72d3
9 changed files with 14052 additions and 10821 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -98,7 +98,7 @@
// Release details // Release details
// These are automatically injected to built HTML // These are automatically injected to built HTML
var build = "1534063312"; var build = "1534105233";
var version = "3.23.2"; var version = "3.23.2";
// Construct the script tag // Construct the script tag

View File

@ -360,11 +360,13 @@ const CoreMiddleware = (function(){
switch (helpers.uriSource(action.uri)){ switch (helpers.uriSource(action.uri)){
case 'spotify': case 'spotify':
store.dispatch(spotifyActions.getTrack(action.uri)); store.dispatch(spotifyActions.getTrack(action.uri));
//store.dispatch(spotifyActions.following(action.uri)); store.dispatch(spotifyActions.following(action.uri));
break; break;
default: default:
if (store.getState().mopidy.connected){
store.dispatch(mopidyActions.getTrack(action.uri)); store.dispatch(mopidyActions.getTrack(action.uri));
}
break; break;
} }
@ -379,7 +381,9 @@ const CoreMiddleware = (function(){
break; break;
default: default:
if (store.getState().mopidy.connected){
store.dispatch(mopidyActions.getAlbum(action.uri)); store.dispatch(mopidyActions.getAlbum(action.uri));
}
break; break;
} }
@ -394,7 +398,9 @@ const CoreMiddleware = (function(){
break; break;
default: default:
if (store.getState().mopidy.connected){
store.dispatch(mopidyActions.getArtist(action.uri)); store.dispatch(mopidyActions.getArtist(action.uri));
}
break; break;
} }
@ -409,7 +415,9 @@ const CoreMiddleware = (function(){
break; break;
default: default:
if (store.getState().mopidy.connected){
store.dispatch(mopidyActions.getPlaylist(action.uri)); store.dispatch(mopidyActions.getPlaylist(action.uri));
}
break; break;
} }

View File

@ -1747,7 +1747,9 @@ const MopidyMiddleware = (function(){
case 'MOPIDY_GET_ALBUM': case 'MOPIDY_GET_ALBUM':
request(socket, store, 'library.lookup', action.data) request(socket, store, 'library.lookup', action.data)
.then(response => { .then(response => {
if (response.length <= 0) return if (response.length <= 0){
return;
}
var album = Object.assign( var album = Object.assign(
{}, {},
@ -1798,11 +1800,7 @@ const MopidyMiddleware = (function(){
} }
} }
store.dispatch({ store.dispatch(coreActions.albumLoaded(album));
type: 'ALBUM_LOADED',
key: album.uri,
album: album
});
}) })
}) })
break; break;
@ -1826,10 +1824,7 @@ const MopidyMiddleware = (function(){
uris.push(response[i].uri); uris.push(response[i].uri);
} }
store.dispatch({ store.dispatch(coreActions.artistsLoaded(response));
type: 'ARTISTS_LOADED',
artists: response
});
store.dispatch({ store.dispatch({
type: 'MOPIDY_LIBRARY_ARTISTS_LOADED', type: 'MOPIDY_LIBRARY_ARTISTS_LOADED',
@ -1921,10 +1916,7 @@ const MopidyMiddleware = (function(){
} }
} }
if (albums){ if (albums){
store.dispatch({ store.dispatch(coreActions.albumsLoaded(albums));
type: 'ALBUMS_LOADED',
albums: albums
});
} }
var artist = Object.assign( var artist = Object.assign(
@ -1936,11 +1928,7 @@ const MopidyMiddleware = (function(){
tracks: response.slice(0,10) tracks: response.slice(0,10)
} }
); );
store.dispatch({ store.dispatch(coreActions.artistLoaded(artist));
type: 'ARTIST_LOADED',
key: artist.uri,
artist: artist
});
// load artwork from LastFM // load artwork from LastFM
var existing_artist = store.getState().core.artists[artist.uri]; var existing_artist = store.getState().core.artists[artist.uri];
@ -1974,10 +1962,7 @@ const MopidyMiddleware = (function(){
} }
} }
store.dispatch({ store.dispatch(coreActions.artistsLoaded(artists));
type: 'ARTISTS_LOADED',
artists: artists
});
// Re-run any consequential processes in 100ms. This allows a small window for other // Re-run any consequential processes in 100ms. This allows a small window for other
// server requests before our next batch. It's a little crude but it means the server isn't // server requests before our next batch. It's a little crude but it means the server isn't
@ -2097,10 +2082,7 @@ const MopidyMiddleware = (function(){
response => { response => {
if (response.length > 0){ if (response.length > 0){
var track = Object.assign({}, response[0]); var track = Object.assign({}, response[0]);
store.dispatch({ store.dispatch(coreActions.trackLoaded(track));
type: 'TRACKS_LOADED',
tracks: [track]
});
} }
}, },
error => { error => {

View File

@ -16,6 +16,7 @@ import ContextMenuTrigger from '../components/ContextMenuTrigger'
import Icon from '../components/Icon' import Icon from '../components/Icon'
import * as helpers from '../helpers' import * as helpers from '../helpers'
import * as coreActions from '../services/core/actions'
import * as uiActions from '../services/ui/actions' import * as uiActions from '../services/ui/actions'
import * as mopidyActions from '../services/mopidy/actions' import * as mopidyActions from '../services/mopidy/actions'
import * as spotifyActions from '../services/spotify/actions' import * as spotifyActions from '../services/spotify/actions'
@ -28,7 +29,7 @@ class Album extends React.Component{
componentDidMount(){ componentDidMount(){
this.setWindowTitle(); this.setWindowTitle();
this.loadAlbum(); this.props.coreActions.loadAlbum(this.props.params.uri);
} }
handleContextMenu(e){ handleContextMenu(e){
@ -41,12 +42,12 @@ class Album extends React.Component{
// if our URI has changed, fetch new album // if our URI has changed, fetch new album
if (nextProps.params.uri != this.props.params.uri){ if (nextProps.params.uri != this.props.params.uri){
this.loadAlbum(nextProps); this.props.coreActions.loadAlbum(nextProps.params.uri);
// if mopidy has just connected AND we're a local album, go get // if mopidy has just connected AND we're a local album, go get
} else if (!this.props.mopidy_connected && nextProps.mopidy_connected){ } else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
if (helpers.uriSource(this.props.params.uri ) != 'spotify'){ if (helpers.uriSource(nextProps.params.uri) != 'spotify'){
this.loadAlbum(nextProps); this.props.coreActions.loadAlbum(nextProps.params.uri);
} }
} }
@ -80,30 +81,6 @@ class Album extends React.Component{
this.props.uiActions.showContextMenu(data); this.props.uiActions.showContextMenu(data);
} }
loadAlbum(props = this.props){
switch(helpers.uriSource(props.params.uri)){
case 'spotify':
if (props.album && props.album.tracks && props.album.artists_uris){
console.info('Loading album from index')
} else {
this.props.spotifyActions.getAlbum(props.params.uri);
}
this.props.spotifyActions.following(props.params.uri);
break;
default:
if (props.mopidy_connected){
if (props.album && props.album.tracks){
console.info('Loading album from index')
} else {
this.props.mopidyActions.getAlbum(props.params.uri);
}
}
break;
}
}
loadMore(){ loadMore(){
this.props.spotifyActions.getMore( this.props.spotifyActions.getMore(
this.props.album.tracks_more, this.props.album.tracks_more,
@ -217,6 +194,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch) spotifyActions: bindActionCreators(spotifyActions, dispatch)

View File

@ -18,6 +18,7 @@ import DropdownField from '../components/Fields/DropdownField'
import Icon from '../components/Icon' import Icon from '../components/Icon'
import * as helpers from '../helpers' import * as helpers from '../helpers'
import * as coreActions from '../services/core/actions'
import * as uiActions from '../services/ui/actions' import * as uiActions from '../services/ui/actions'
import * as mopidyActions from '../services/mopidy/actions' import * as mopidyActions from '../services/mopidy/actions'
import * as pusherActions from '../services/pusher/actions' import * as pusherActions from '../services/pusher/actions'
@ -384,6 +385,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch),
pusherActions: bindActionCreators(pusherActions, dispatch), pusherActions: bindActionCreators(pusherActions, dispatch),

View File

@ -19,6 +19,7 @@ import Icon from '../components/Icon'
import Popularity from '../components/Popularity' import Popularity from '../components/Popularity'
import * as helpers from '../helpers' import * as helpers from '../helpers'
import * as coreActions from '../services/core/actions'
import * as uiActions from '../services/ui/actions' import * as uiActions from '../services/ui/actions'
import * as mopidyActions from '../services/mopidy/actions' import * as mopidyActions from '../services/mopidy/actions'
import * as spotifyActions from '../services/spotify/actions' import * as spotifyActions from '../services/spotify/actions'
@ -307,7 +308,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {
uiActions: bindActionCreators(uiActions, dispatch), coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch),
lastfmActions: bindActionCreators(lastfmActions, dispatch), lastfmActions: bindActionCreators(lastfmActions, dispatch),

View File

@ -12,6 +12,7 @@ import ContextMenuTrigger from '../components/ContextMenuTrigger'
import Icon from '../components/Icon' import Icon from '../components/Icon'
import * as helpers from '../helpers' import * as helpers from '../helpers'
import * as coreActions from '../services/core/actions'
import * as uiActions from '../services/ui/actions' import * as uiActions from '../services/ui/actions'
import * as mopidyActions from '../services/mopidy/actions' import * as mopidyActions from '../services/mopidy/actions'
import * as spotifyActions from '../services/spotify/actions' import * as spotifyActions from '../services/spotify/actions'
@ -143,6 +144,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch) spotifyActions: bindActionCreators(spotifyActions, dispatch)
} }