Local assets

This commit is contained in:
James Barnsley
2017-01-15 21:06:24 +13:00
parent 8b15e024cd
commit 838255b34b
9 changed files with 120 additions and 64 deletions

View File

@ -13,12 +13,7 @@ export default class Thumbnail extends React.Component{
shouldComponentUpdate(nextProps, nextState){
// no images at all, and we already know it
if(
typeof(nextProps.image) == 'undefined' &&
typeof(this.props.image) == 'undefined' &&
typeof(nextProps.images) == 'undefined' &&
typeof(this.props.images) == 'undefined'
) return false
if (!nextProps.image && !this.props.image && !nextProps.images && !this.props.images) return false
// image changed
if( !this.props.image && nextProps.image ) return true

View File

@ -27,11 +27,8 @@ const sendRequest = ( dispatch, getState, params ) => {
})
}
export function getArtist( artist, mbid = false ){
export function getArtist( uri, artist, mbid = false ){
return (dispatch, getState) => {
dispatch({ type: 'LASTFM_ARTIST_LOADED', data: false });
if( mbid ){
var params = 'method=artist.getInfo&mbid='+mbid
}else{
@ -43,8 +40,12 @@ export function getArtist( artist, mbid = false ){
response => {
if( response.artist ){
dispatch({
type: 'LASTFM_ARTIST_LOADED',
data: response.artist
type: 'ARTIST_LOADED',
uri: uri,
artist: {
images: response.artist.image,
bio: response.artist.bio
}
});
}
}

View File

@ -175,13 +175,6 @@ export function getDirectory( uri ){
}
}
export function getAlbum( uri ){
return {
type: 'MOPIDY_GET_ALBUM',
data: { uri: uri }
}
}
export function getArtist( uri ){
return {
type: 'MOPIDY_GET_ARTIST',
@ -195,6 +188,13 @@ export function getArtists(){
}
}
export function getAlbum( uri ){
return {
type: 'MOPIDY_GET_ALBUM',
data: { uri: uri }
}
}
export function getAlbums(){
return {
type: 'MOPIDY_GET_ALBUMS'

View File

@ -509,16 +509,21 @@ const MopidyMiddleware = (function(){
* ======================================================================================
**/
case 'MOPIDY_ALBUMS':
store.dispatch({ type: 'MOPIDY_ALBUMS_LOADED', data: false });
case 'MOPIDY_GET_ALBUMS':
instruct( socket, store, 'library.browse', { uri: 'local:directory?type=album' } )
.then( response => {
store.dispatch({ type: 'MOPIDY_ALBUMS_LOADED', data: response });
.then( response => {
store.dispatch({
type: 'ALBUMS_LOADED',
albums: response
});
store.dispatch({
type: 'LOCAL_ALBUMS_LOADED',
uris: helpers.asURIs(response)
});
})
break;
case 'MOPIDY_ALBUM':
//store.dispatch({ type: 'MOPIDY_ALBUM_LOADED', data: false });
case 'MOPIDY_GET_ALBUM':
instruct( socket, store, 'library.lookup', action.data )
.then( response => {
var album = Object.assign(
@ -570,7 +575,11 @@ const MopidyMiddleware = (function(){
}
}
store.dispatch({ type: 'MOPIDY_ALBUM_LOADED', data: album });
store.dispatch({
type: 'ALBUM_LOADED',
uri: album.uri,
album: album
});
})
})
break;
@ -581,45 +590,66 @@ const MopidyMiddleware = (function(){
* ======================================================================================
**/
case 'MOPIDY_ARTISTS':
store.dispatch({ type: 'MOPIDY_ARTISTS_LOADED', data: false });
case 'MOPIDY_GET_ARTISTS':
store.dispatch({ type: 'LOCAL_ARTISTS_LOADED', data: false });
instruct( socket, store, 'library.browse', { uri: 'local:directory?type=artist' } )
.then( response => {
store.dispatch({ type: 'MOPIDY_ARTISTS_LOADED', data: response });
store.dispatch({
type: 'ARTISTS_LOADED',
artists: response
});
store.dispatch({
type: 'LOCAL_ARTISTS_LOADED',
uris: helpers.asURIs(response)
});
})
break;
case 'MOPIDY_ARTIST':
store.dispatch({ type: 'MOPIDY_ARTIST_LOADED', data: false });
case 'MOPIDY_GET_ARTIST':
instruct( socket, store, 'library.lookup', action.data )
.then( response => {
var artist = response[0].artists[0];
if( !artist.images ) artist.images = [];
if( !artist.albums ) artist.albums = [];
artist.tracks = response.slice(0,10);
.then( response => {
var albums = []
for( var i = 0; i < response.length; i++ ){
var album = response[i].album;
function getByURI( albumToCheck ){
return album.uri == albumToCheck.uri
}
var existingAlbum = artist.albums.find(getByURI);
var existingAlbum = albums.find(getByURI);
if( !existingAlbum ){
artist.albums.push(album)
albums.push(album)
}
}
store.dispatch({
type: 'ALBUMS_LOADED',
albums: albums
})
var artist = Object.assign(
{},
response[0].artists[0],
{
images: [],
albums_uris: helpers.asURIs(albums),
tracks: response.slice(0,10)
}
)
// load artwork from LastFM
if( artist.images.length <= 0 ){
if( artist.musicbrainz_id ){
store.dispatch( lastfmActions.getArtist( false, artist.musicbrainz_id ) )
store.dispatch( lastfmActions.getArtist( artist.uri, false, artist.musicbrainz_id ) )
}else{
store.dispatch( lastfmActions.getArtist( artist.name ) )
store.dispatch( lastfmActions.getArtist( artist.uri, artist.name.replace('&','and') ) )
}
}
store.dispatch({ type: 'MOPIDY_ARTIST_LOADED', data: artist });
store.dispatch({
type: 'ARTIST_LOADED',
uri: artist.uri,
artist: artist
});
})
break;

View File

@ -172,6 +172,10 @@ export default function reducer(ui = {}, action){
library_albums_total: action.total
});
case 'LOCAL_ALBUMS_LOADED':
if (!action.uris) return Object.assign({}, ui, { local_albums: null });
return Object.assign({}, ui, { local_albums: action.uris });
case 'NEW_RELEASES_LOADED':
if (!action.uris){
return Object.assign({}, ui, {
@ -268,6 +272,10 @@ export default function reducer(ui = {}, action){
library_artists_total: action.total
});
case 'LOCAL_ARTISTS_LOADED':
if (!action.uris) return Object.assign({}, ui, { local_artists: null });
return Object.assign({}, ui, { local_artists: action.uris });
/**
* User

View File

@ -54,7 +54,13 @@ class Album extends React.Component{
break;
case 'local':
if( props.mopidy_connected ) this.props.mopidyActions.getAlbum( props.params.uri );
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;
}
}

View File

@ -49,7 +49,7 @@ class Artist extends React.Component{
componentWillUpdate( nextProps, nextState ){
if( nextState.sub_view != this.state.sub_view && nextState.sub_view == 'biography' ){
if( this.props.artist && !this.props.artist.bio ){
this.props.lastfmActions.getArtist( this.props.artist.name.replace('&','and') )
this.props.lastfmActions.getArtist( this.props.params.uri, this.props.artist.name.replace('&','and') )
}
}
}
@ -66,7 +66,13 @@ class Artist extends React.Component{
break
case 'local':
this.props.mopidyActions.getArtist( props.params.uri );
if (props.mopidy_connected){
if (props.artist && props.artist.images){
console.info('Loading local artist from index')
} else {
this.props.mopidyActions.getArtist( props.params.uri );
}
}
break
}
@ -91,9 +97,7 @@ class Artist extends React.Component{
<span className={'option '+( this.state.sub_view == 'overview' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'overview' })}>
Overview
</span>
<span className={'option '+( this.state.sub_view == 'related_artists' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'related_artists' })}>
Related artists
</span>
{this.props.artist.related_artists_uris ? <span className={'option '+( this.state.sub_view == 'related_artists' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'related_artists' })}>Related artists</span> : null}
<span className={'option '+( this.state.sub_view == 'biography' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'biography' })}>
Biography
</span>
@ -102,7 +106,6 @@ class Artist extends React.Component{
}
renderBody(){
var related_artists = []
if (this.props.artist.related_artists_uris){
for (var i = 0; i < this.props.artist.related_artists_uris.length; i++){
@ -145,20 +148,16 @@ class Artist extends React.Component{
)
}
// default body
return (
<div className="body overview">
<div className="col w70">
<div className={this.props.artist.related_artists ? "col w70" : "col w100"}>
<h4 className="left-padding">Top tracks</h4>
{ this.props.artist.tracks ? <TrackList tracks={ this.props.artist.tracks } /> : null }
</div>
<div className="col w5"></div>
<div className="col w25 related-artists">
<h4>Related artists</h4>
<ArtistList artists={related_artists.slice(0,6)} />
</div>
{this.props.artist.related_artists ? <div className="col w25 related-artists"><h4>Related artists</h4><ArtistList artists={related_artists.slice(0,6)} /></div> : null}
<div className="cf"></div>
@ -175,7 +174,7 @@ class Artist extends React.Component{
if( !this.props.artist ) return null
var scheme = helpers.uriSource( this.props.params.uri );
var image = false
var image = null
if( this.props.artist.images ) image = helpers.sizedImages( this.props.artist.images ).huge
return (

View File

@ -15,7 +15,6 @@ class LibraryLocalAlbums extends React.Component{
super(props);
}
// on render
componentDidMount(){
this.loadAlbums()
}
@ -33,13 +32,21 @@ class LibraryLocalAlbums extends React.Component{
}
render(){
if( !this.props.albums ) return null
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])
}
}
}
return (
<div className="view library-local-view">
<Header icon="music" title="Local albums" />
<div>
<List columns={[{ name: 'name', width: '100'}]} rows={this.props.albums} link_prefix={global.baseURL+"album/"} />
<List columns={[{ name: 'name', width: '100'}]} rows={albums} link_prefix={global.baseURL+"album/"} />
</div>
</div>
);
@ -56,7 +63,8 @@ class LibraryLocalAlbums extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
mopidy_connected: state.mopidy.connected,
albums: state.mopidy.albums
local_albums: state.ui.local_albums,
albums: state.ui.albums
}
}

View File

@ -27,19 +27,27 @@ class LibraryLocalArtists extends React.Component{
}
loadArtists(props = this.props){
if( props.mopidy_connected ){
if( props.mopidy_connected && !props.local_artists ){
this.props.mopidyActions.getArtists();
}
}
render(){
if( !this.props.artists ) return null
var artists = []
if (this.props.artists && this.props.local_artists){
for (var i = 0; i < this.props.local_artists.length; i++){
var uri = this.props.local_artists[i]
if (this.props.artists.hasOwnProperty(uri)){
artists.push(this.props.artists[uri])
}
}
}
return (
<div className="view library-local-view">
<Header icon="music" title="Local artists" />
<section className="list-wrapper">
<List columns={[{ name: 'name', width: '100'}]} rows={this.props.artists} link_prefix={global.baseURL+"artist/"} />
<List columns={[{ name: 'name', width: '100'}]} rows={artists} link_prefix={global.baseURL+"artist/"} />
</section>
</div>
);
@ -56,7 +64,8 @@ class LibraryLocalArtists extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
mopidy_connected: state.mopidy.connected,
artists: state.mopidy.artists
local_artists: state.ui.local_artists,
artists: state.ui.artists
}
}