Loading library albums as process; Processes loader for less jammy animation
This commit is contained in:
9
src/js/bootstrap.js
vendored
9
src/js/bootstrap.js
vendored
@ -30,12 +30,17 @@ let reducers = combineReducers({
|
||||
var initialState = {
|
||||
core: {
|
||||
current_tracklist: [],
|
||||
current_tltrack: false
|
||||
current_tltrack: false,
|
||||
albums: {},
|
||||
users: {},
|
||||
playlists: {},
|
||||
artists: {}
|
||||
},
|
||||
ui: {
|
||||
slim_mode: false,
|
||||
selected_tracks: [],
|
||||
notifications: []
|
||||
notifications: [],
|
||||
processes: {}
|
||||
},
|
||||
mopidy: {
|
||||
connected: false,
|
||||
|
||||
@ -48,14 +48,16 @@ export default class Notifications extends React.Component{
|
||||
if (processes[key].cancelling){
|
||||
items.push(
|
||||
<div className="process notification cancelling" key={key}>
|
||||
<div className="loader"></div>
|
||||
Cancelling
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
items.push(
|
||||
<div className="process notification" key={key}>
|
||||
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.cancelProcess(key) } />
|
||||
<div className="loader"></div>
|
||||
{ processes[key].content }
|
||||
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.cancelProcess(key) } />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ class Thumbnail extends React.Component{
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: ascertain whether this is improving or hindering performance
|
||||
// The UI appears to work perfectly fine without this
|
||||
shouldComponentUpdate(nextProps, nextState){
|
||||
@ -22,23 +22,24 @@ class Thumbnail extends React.Component{
|
||||
if (!nextProps.image && !this.props.image && !nextProps.images && !this.props.images) return false
|
||||
|
||||
// image changed
|
||||
if( !this.props.image && nextProps.image ) return true
|
||||
if( this.props.image && nextProps.image ) return true
|
||||
if( this.props.image != nextProps.image ) return true
|
||||
if (!this.props.image && nextProps.image) return true
|
||||
if (this.props.image && nextProps.image) return true
|
||||
if (this.props.image != nextProps.image) return true
|
||||
|
||||
// images array changed
|
||||
if( typeof(this.props.images) === 'undefined' && nextProps.images ) return true
|
||||
if( this.props.images && typeof(nextProps.images) === 'undefined' ) return true
|
||||
if( this.props.images.length != nextProps.images.length ) return true
|
||||
if (this.props.images === undefined && nextProps.images ) return true
|
||||
if (this.props.images && nextProps.images === undefined) return true
|
||||
if (this.props.images && !nextProps.images || this.props.images.length != nextProps.images.length ) return true
|
||||
|
||||
// image item changed
|
||||
var size = 'medium'
|
||||
var images = helpers.sizedImages( nextProps.images )
|
||||
if( this.props.size ) size = this.props.size
|
||||
if( this.props.images[size] != images[size] ) return true
|
||||
if (this.props.size ) size = this.props.size
|
||||
if (this.props.images[size] != images[size]) return true
|
||||
|
||||
return false
|
||||
}
|
||||
*/
|
||||
|
||||
mapImageSizes( props = this.props ){
|
||||
|
||||
@ -79,7 +80,7 @@ class Thumbnail extends React.Component{
|
||||
return (
|
||||
<div className={class_name}>
|
||||
|
||||
<LazyLoad height={10} placeholder={<div className="image"></div>}>
|
||||
<LazyLoad height={600} placeholder={<div className="image"></div>}>
|
||||
<div className="image loaded" style={{backgroundImage: 'url("'+image+'")'}}></div>
|
||||
</LazyLoad>
|
||||
|
||||
|
||||
@ -35,7 +35,6 @@ import LibraryTracks from './views/library/LibraryTracks'
|
||||
import LibraryPlaylists from './views/library/LibraryPlaylists'
|
||||
import LibraryBrowse from './views/library/LibraryBrowse'
|
||||
import LibraryLocalArtists from './views/library/LibraryLocalArtists'
|
||||
import LibraryLocalAlbums from './views/library/LibraryLocalAlbums'
|
||||
|
||||
// setup our analytics tracking
|
||||
ReactGA.initialize('UA-64701652-3');
|
||||
@ -76,7 +75,6 @@ ReactDOM.render(
|
||||
<Route path="library/tracks" component={LibraryTracks} />
|
||||
<Route path="library/playlists" component={LibraryPlaylists} />
|
||||
<Route path="library/browse/local-artists" component={LibraryLocalArtists} />
|
||||
<Route path="library/browse/local-albums" component={LibraryLocalAlbums} />
|
||||
<Route path="library/browse(/:uri)" component={LibraryBrowse} />
|
||||
|
||||
</Route>
|
||||
|
||||
@ -217,10 +217,11 @@ export function getAlbum( uri ){
|
||||
}
|
||||
}
|
||||
|
||||
export function getAlbums( uris ){
|
||||
export function getAlbums(uris, processor = null){
|
||||
return {
|
||||
type: 'MOPIDY_GET_ALBUMS',
|
||||
uris: uris
|
||||
uris: uris,
|
||||
processor: processor
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,6 +231,18 @@ export function getLibraryAlbums(){
|
||||
}
|
||||
}
|
||||
|
||||
export function runProcessor(processor){
|
||||
return {
|
||||
type: processor
|
||||
}
|
||||
}
|
||||
|
||||
export function cancelProcessor(processor){
|
||||
return {
|
||||
type: processor+'_CANCEL'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searching
|
||||
|
||||
@ -840,22 +840,47 @@ const MopidyMiddleware = (function(){
|
||||
.then( response => {
|
||||
if (response.length <= 0) return
|
||||
|
||||
var uris = helpers.arrayOf('uri',response)
|
||||
|
||||
/*
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_GET_ALBUMS',
|
||||
uris: uris//.slice(0,50) THIS PAGINATES REQUESTS. Slow servers might need this...
|
||||
});
|
||||
*/
|
||||
|
||||
store.dispatch({
|
||||
type: 'LIBRARY_ALBUMS_LOADED',
|
||||
uris: uris
|
||||
uris: helpers.arrayOf('uri',response)
|
||||
});
|
||||
|
||||
// Start our process to load the full album objects
|
||||
store.dispatch(mopidyActions.runProcessor('MOPIDY_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
})
|
||||
break;
|
||||
|
||||
case 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR':
|
||||
|
||||
if (store.getState().ui.processes['MOPIDY_LIBRARY_ALBUMS'] !== undefined){
|
||||
var processor = store.getState().ui.processes['MOPIDY_LIBRARY_ALBUMS']
|
||||
|
||||
if (processor.cancelling){
|
||||
store.dispatch(uiActions.stopProcess('MOPIDY_LIBRARY_ALBUMS'))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
store.dispatch(uiActions.startProcess('MOPIDY_LIBRARY_ALBUMS', 'Loading album library'))
|
||||
|
||||
// Figure out the remaining items
|
||||
var library_uris = store.getState().core.library_albums
|
||||
var to_load = []
|
||||
for (var i = 0; i < library_uris.length && to_load.length < 50; i++){
|
||||
var uri = library_uris[i]
|
||||
if (helpers.uriSource(uri) == 'local' && store.getState().core.albums[uri] === undefined){
|
||||
to_load.push(uri)
|
||||
}
|
||||
}
|
||||
|
||||
if (to_load.length > 0){
|
||||
store.dispatch(mopidyActions.getAlbums(to_load, 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
} else {
|
||||
store.dispatch(uiActions.stopProcess('MOPIDY_LIBRARY_ALBUMS'))
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
case 'MOPIDY_GET_ALBUMS':
|
||||
instruct( socket, store, 'library.lookup', { uris: action.uris } )
|
||||
.then( response => {
|
||||
@ -883,7 +908,19 @@ const MopidyMiddleware = (function(){
|
||||
store.dispatch({
|
||||
type: 'ALBUMS_LOADED',
|
||||
albums: albums
|
||||
});
|
||||
})
|
||||
|
||||
// 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
|
||||
// locked until we're completely done.
|
||||
if (action.processor){
|
||||
setTimeout(
|
||||
function(){
|
||||
store.dispatch(mopidyActions.runProcessor(action.processor))
|
||||
},
|
||||
100
|
||||
)
|
||||
}
|
||||
})
|
||||
break;
|
||||
|
||||
|
||||
@ -126,6 +126,9 @@ const UIMiddleware = (function(){
|
||||
if (action.key == 'MOPIDY_ENQUEUE_URIS'){
|
||||
store.dispatch(mopidyActions.enqueueURIsCancel())
|
||||
}
|
||||
if (action.key == 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR'){
|
||||
store.dispatch(mopidyActions.cancelProcessor(action.key))
|
||||
}
|
||||
next(action)
|
||||
break
|
||||
|
||||
|
||||
@ -1,203 +0,0 @@
|
||||
|
||||
import React, { PropTypes } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
|
||||
import AlbumGrid from '../../components/AlbumGrid'
|
||||
import Header from '../../components/Header'
|
||||
import DropdownField from '../../components/DropdownField'
|
||||
import List from '../../components/List'
|
||||
import LazyLoadListener from '../../components/LazyLoadListener'
|
||||
|
||||
import * as helpers from '../../helpers'
|
||||
import * as uiActions from '../../services/ui/actions'
|
||||
import * as mopidyActions from '../../services/mopidy/actions'
|
||||
import * as spotifyActions from '../../services/spotify/actions'
|
||||
|
||||
class LibraryLocalAlbums extends React.Component{
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
this.loadAlbums()
|
||||
}
|
||||
|
||||
componentWillReceiveProps( nextProps ){
|
||||
if (!this.props.mopidy_connected && nextProps.mopidy_connected){
|
||||
this.loadAlbums(nextProps);
|
||||
}
|
||||
}
|
||||
|
||||
loadAlbums(props = this.props){
|
||||
if (props.mopidy_connected && !this.props.local_albums){
|
||||
this.props.mopidyActions.getLibraryAlbums();
|
||||
}
|
||||
}
|
||||
|
||||
moreURIsToLoad(){
|
||||
var uris = []
|
||||
if (this.props.albums && this.props.local_albums){
|
||||
for (var i = 0; i < this.props.local_albums.length; i++){
|
||||
var uri = this.props.local_albums[i]
|
||||
if (!this.props.albums.hasOwnProperty(uri)){
|
||||
uris.push(uri)
|
||||
}
|
||||
|
||||
// limit each lookup to 50 URIs
|
||||
if (uris.length >= 50) break
|
||||
}
|
||||
}
|
||||
|
||||
return uris
|
||||
}
|
||||
|
||||
loadMore(){
|
||||
var uris = this.moreURIsToLoad()
|
||||
this.props.mopidyActions.getAlbums(uris)
|
||||
}
|
||||
|
||||
setSort(value){
|
||||
var reverse = false
|
||||
if( this.props.sort == value ) reverse = !this.props.sort_reverse
|
||||
|
||||
var data = {
|
||||
library_local_albums_sort_reverse: reverse,
|
||||
library_local_albums_sort: value
|
||||
}
|
||||
this.props.uiActions.set(data)
|
||||
}
|
||||
|
||||
renderView(albums){
|
||||
if( this.props.view == 'list' ){
|
||||
|
||||
var columns = [
|
||||
{
|
||||
label: 'Name',
|
||||
name: 'name',
|
||||
width: 40
|
||||
},
|
||||
{
|
||||
label: 'Artists',
|
||||
name: 'artists',
|
||||
width: 30
|
||||
},
|
||||
{
|
||||
label: 'Tracks',
|
||||
name: 'tracks_total',
|
||||
width: 15
|
||||
}
|
||||
]
|
||||
|
||||
return (
|
||||
<section className="content-wrapper">
|
||||
<List
|
||||
columns={columns}
|
||||
rows={albums}
|
||||
className="library-local-album-list"
|
||||
link_prefix={global.baseURL+"album/"} />
|
||||
</section>
|
||||
)
|
||||
}else{
|
||||
return (
|
||||
<section className="content-wrapper">
|
||||
<AlbumGrid albums={albums} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
render(){
|
||||
var albums = []
|
||||
if (this.props.albums && this.props.local_albums){
|
||||
for (var i = 0; i < this.props.local_albums.length; i++){
|
||||
var uri = this.props.local_albums[i]
|
||||
if (this.props.albums.hasOwnProperty(uri)){
|
||||
albums.push(this.props.albums[uri])
|
||||
}
|
||||
}
|
||||
|
||||
if( this.props.sort ){
|
||||
albums = helpers.sortItems(albums, this.props.sort, this.props.sort_reverse)
|
||||
}
|
||||
}
|
||||
|
||||
var view_options = [
|
||||
{
|
||||
value: 'thumbnails',
|
||||
label: 'Thumbnails'
|
||||
},
|
||||
{
|
||||
value: 'list',
|
||||
label: 'List'
|
||||
}
|
||||
]
|
||||
|
||||
var sort_options = [
|
||||
{
|
||||
value: 'name',
|
||||
label: 'Name'
|
||||
},
|
||||
{
|
||||
value: 'tracks_total',
|
||||
label: 'Tracks'
|
||||
}
|
||||
]
|
||||
|
||||
var options = (
|
||||
<span>
|
||||
<DropdownField icon="sort" name="Sort" value={this.props.sort} options={sort_options} reverse={this.props.sort_reverse} handleChange={val => {this.setSort(val); this.props.uiActions.hideContextMenu() }} />
|
||||
<DropdownField icon="eye" name="View" value={this.props.view} options={view_options} handleChange={val => {this.props.uiActions.set({ library_local_albums_view: val }); this.props.uiActions.hideContextMenu() }} />
|
||||
</span>
|
||||
)
|
||||
|
||||
if (albums.length <= 0 && helpers.isLoading(this.props.load_queue,['mopidy_lookup','mopidy_browse'])){
|
||||
return (
|
||||
<div className="view library-local-view">
|
||||
<Header icon="music" title="Local albums" options={options} uiActions={this.props.uiActions} />
|
||||
<div className="body-loader loading">
|
||||
<div className="loader"></div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="view library-local-view">
|
||||
<Header icon="music" title="Local albums" options={options} uiActions={this.props.uiActions} />
|
||||
{this.renderView(albums)}
|
||||
<LazyLoadListener enabled={(this.moreURIsToLoad().length > 0)} loadMore={ () => this.loadMore() }/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export our component
|
||||
*
|
||||
* We also integrate our global store, using connect()
|
||||
**/
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
load_queue: state.ui.load_queue,
|
||||
mopidy_connected: state.mopidy.connected,
|
||||
albums: state.core.albums,
|
||||
local_albums: state.core.local_albums,
|
||||
view: state.ui.library_local_albums_view,
|
||||
sort: (state.ui.library_local_albums_sort ? state.ui.library_local_albums_sort : 'name'),
|
||||
sort_reverse: (state.ui.library_local_albums_sort_reverse ? true : false)
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
uiActions: bindActionCreators(uiActions, dispatch),
|
||||
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
||||
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(LibraryLocalAlbums)
|
||||
Reference in New Issue
Block a user