Merging SearchResult.Artist and SearchResult.Album arrays in favor of digested SearchResult.Track assumptions, fixes #244
This commit is contained in:
@ -41,6 +41,7 @@ class AlbumGrid extends React.Component{
|
||||
key={album.uri}
|
||||
type="album"
|
||||
item={album}
|
||||
show_source_icon={this.props.show_source_icon}
|
||||
onClick={e => {hashHistory.push(global.baseURL+'album/'+encodeURIComponent(album.uri))}}
|
||||
onLoad={() => this.handleLoad(album.uri)}
|
||||
onContextMenu={e => this.handleContextMenu(e,album)}
|
||||
|
||||
@ -48,9 +48,9 @@ class ArtistGrid extends React.Component{
|
||||
<Thumbnail size="medium" images={artist.images} />
|
||||
<div className="name">
|
||||
{artist.name}
|
||||
{this.props.show_source_icon ? <FontAwesome name={helpers.sourceIcon(artist.uri)} className="source" fixedWidth /> : null}
|
||||
</div>
|
||||
<div className="secondary">
|
||||
{this.props.show_source_icon ? <FontAwesome name={helpers.sourceIcon(artist.uri)} className="source" /> : null}
|
||||
{artist.followers ? artist.followers.total.toLocaleString()+' followers' : null}
|
||||
{artist.albums_uris && !artist.followers ? artist.albums_uris.length+' albums' : null}
|
||||
</div>
|
||||
|
||||
@ -4,6 +4,7 @@ import ReactDOM from 'react-dom'
|
||||
import { Router, Link, hashHistory } from 'react-router'
|
||||
import FontAwesome from 'react-fontawesome'
|
||||
|
||||
import * as helpers from '../helpers'
|
||||
import Thumbnail from './Thumbnail'
|
||||
import ArtistSentence from './ArtistSentence'
|
||||
|
||||
@ -36,38 +37,38 @@ export default class GridItem extends React.Component{
|
||||
|
||||
case 'playlist':
|
||||
return (
|
||||
<div className="secondary">
|
||||
<span>
|
||||
{item.tracks_total ? item.tracks_total : 0} tracks
|
||||
</div>
|
||||
</span>
|
||||
)
|
||||
break
|
||||
|
||||
case 'artist':
|
||||
return (
|
||||
<div className="secondary">
|
||||
<span>
|
||||
{item.followers ? item.followers.total.toLocaleString()+' followers' : item.albums_uris.length+' albums'}
|
||||
</div>
|
||||
</span>
|
||||
)
|
||||
break
|
||||
|
||||
case 'album':
|
||||
return (
|
||||
<div className="secondary">
|
||||
<span>
|
||||
{item.artists ? <ArtistSentence artists={item.artists} /> : null}
|
||||
</div>
|
||||
</span>
|
||||
)
|
||||
break
|
||||
|
||||
default:
|
||||
return (
|
||||
<div className="secondary">
|
||||
<span>
|
||||
{ item.artists ? <ArtistSentence artists={ item.artists } /> : null }
|
||||
{ item.followers ? item.followers.total.toLocaleString()+' followers' : null }
|
||||
</div>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
return output
|
||||
return output;
|
||||
}
|
||||
|
||||
render(){
|
||||
@ -88,8 +89,13 @@ export default class GridItem extends React.Component{
|
||||
return (
|
||||
<div className="grid-item" onClick={e => this.handleClick(e)} onContextMenu={e => this.handleContextMenu(e)}>
|
||||
<Thumbnail size="medium" images={images} />
|
||||
<div className="name">{item.name ? item.name : <span className="dark-grey-text">{item.uri}</span>}</div>
|
||||
{ this.renderSecondary(item) }
|
||||
<div className="name">
|
||||
{item.name ? item.name : <span className="dark-grey-text">{item.uri}</span>}
|
||||
</div>
|
||||
<div className="secondary">
|
||||
{this.props.show_source_icon ? <FontAwesome name={helpers.sourceIcon(item.uri)} className="source" /> : null}
|
||||
{this.renderSecondary(item)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ class PlaylistGrid extends React.Component{
|
||||
key={playlist.uri}
|
||||
type="playlist"
|
||||
item={playlist}
|
||||
show_source_icon={this.props.show_source_icon}
|
||||
onClick={e => {hashHistory.push(global.baseURL+'playlist/'+encodeURIComponent(playlist.uri))}}
|
||||
onContextMenu={e => this.handleContextMenu(e,playlist)}
|
||||
/>
|
||||
|
||||
@ -649,10 +649,15 @@ const MopidyMiddleware = (function(){
|
||||
instruct(socket, store, 'library.search', {query: {album: [action.data.query]}, uris: [action.data.uri_scheme]})
|
||||
.then(
|
||||
response => {
|
||||
if (response.length > 0){
|
||||
if (response.length > 0){
|
||||
var albums = [];
|
||||
|
||||
// collate all our different sources into one array
|
||||
var albums = []
|
||||
// Merge our proper album response container
|
||||
if (response[0].albums){
|
||||
albums = [...response[0].albums, ...albums];
|
||||
}
|
||||
|
||||
// Pull the Album objects from our track responses
|
||||
if (response[0].tracks){
|
||||
for (var i = 0; i < response[0].tracks.length; i++){
|
||||
if (response[0].tracks[i].album !== undefined && response[0].tracks[i].album.uri !== undefined){
|
||||
@ -661,7 +666,6 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: limit uris at the loop, rather than post loop for performance
|
||||
var albums_uris = helpers.arrayOf('uri',albums)
|
||||
albums_uris = helpers.removeDuplicates(albums_uris)
|
||||
|
||||
@ -715,7 +719,16 @@ const MopidyMiddleware = (function(){
|
||||
.then(
|
||||
response => {
|
||||
if (response.length > 0){
|
||||
var artists_uris = []
|
||||
var artists_uris = [];
|
||||
|
||||
// Pull actual artist objects
|
||||
if (response[0].artists){
|
||||
for (var i = 0; i < response[0].artists.length; i++){
|
||||
artists_uris.push(response[0].artists.uri);
|
||||
}
|
||||
}
|
||||
|
||||
// Digest track artists into actual artist results
|
||||
if (response[0].tracks){
|
||||
for (var i = 0; i < response[0].tracks.length; i++){
|
||||
if (response[0].tracks[i].artists){
|
||||
@ -729,12 +742,11 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: limit uris at the loop, rather than post loop for performance
|
||||
artists_uris = helpers.removeDuplicates(artists_uris)
|
||||
artists_uris = helpers.removeDuplicates(artists_uris);
|
||||
|
||||
// load each artist
|
||||
for (var i = 0; i < artists_uris.length; i++){
|
||||
store.dispatch(mopidyActions.getArtist(artists_uris[i]))
|
||||
store.dispatch(mopidyActions.getArtist(artists_uris[i]));
|
||||
}
|
||||
|
||||
// and plug in their URIs
|
||||
@ -773,8 +785,8 @@ const MopidyMiddleware = (function(){
|
||||
.then(
|
||||
response => {
|
||||
if (response.length > 0){
|
||||
var playlists_uris = [];
|
||||
|
||||
var playlists_uris = []
|
||||
for (var i = 0; i < response.length; i++){
|
||||
var playlist = response[i]
|
||||
if (playlist.name.includes(action.data.query) && action.data.uri_schemes.includes(helpers.uriSource(playlist.uri)+':')){
|
||||
@ -782,8 +794,6 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
playlists_uris = playlists_uris
|
||||
|
||||
// load each playlist
|
||||
for (var i = 0; i < playlists_uris.length; i++){
|
||||
store.dispatch(mopidyActions.getPlaylist(playlists_uris[i]))
|
||||
@ -833,7 +843,7 @@ const MopidyMiddleware = (function(){
|
||||
.then(
|
||||
response => {
|
||||
if (response.length > 0 && response[0].tracks !== undefined){
|
||||
var tracks = response[0].tracks
|
||||
var tracks = response[0].tracks;
|
||||
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
@ -867,9 +877,8 @@ const MopidyMiddleware = (function(){
|
||||
instruct(socket, store, 'library.search', {query: {any: [action.data.query]}, uris: [action.data.uri_scheme]})
|
||||
.then(
|
||||
response => {
|
||||
console.log(response)
|
||||
if (response.length > 0 && response[0].tracks !== undefined){
|
||||
var tracks = response[0].tracks
|
||||
var tracks = response[0].tracks;
|
||||
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
@ -901,9 +910,14 @@ const MopidyMiddleware = (function(){
|
||||
.then(
|
||||
response => {
|
||||
if (response.length > 0){
|
||||
var albums = [];
|
||||
|
||||
// collate all our different sources into one array
|
||||
var albums = []
|
||||
// Merge actual album responses first
|
||||
if (response[0].albums){
|
||||
albums = [...response[0].albums, ...albums];
|
||||
}
|
||||
|
||||
// Then digest tracks albums
|
||||
if (response[0].tracks){
|
||||
for (var i = 0; i < response[0].tracks.length; i++){
|
||||
if (response[0].tracks[i].album !== undefined && response[0].tracks[i].album.uri !== undefined){
|
||||
@ -912,7 +926,6 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: limit uris at the loop, rather than post loop for performance
|
||||
var albums_uris = helpers.arrayOf('uri',albums)
|
||||
albums_uris = helpers.removeDuplicates(albums_uris)
|
||||
|
||||
@ -953,7 +966,16 @@ const MopidyMiddleware = (function(){
|
||||
.then(
|
||||
response => {
|
||||
if (response.length > 0){
|
||||
var artists_uris = []
|
||||
var artists_uris = [];
|
||||
|
||||
// Pull our actual artists objects
|
||||
if (response[0].artists){
|
||||
for (var i = 0; i < response[0].artists.length; i++){
|
||||
artists_uris.push(response[0].artists.uri);
|
||||
}
|
||||
}
|
||||
|
||||
// Digest tracks artists
|
||||
if (response[0].tracks){
|
||||
for (var i = 0; i < response[0].tracks.length; i++){
|
||||
if (response[0].tracks[i].artists){
|
||||
@ -967,7 +989,6 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: limit uris at the loop, rather than post loop for performance
|
||||
artists_uris = helpers.removeDuplicates(artists_uris)
|
||||
|
||||
// load each artist
|
||||
|
||||
@ -25,11 +25,10 @@
|
||||
@include one_line_text;
|
||||
padding-top: 2px;
|
||||
color: $secondary_grey;
|
||||
}
|
||||
|
||||
.source {
|
||||
color: $secondary_grey;
|
||||
padding-left: 2px;
|
||||
.source {
|
||||
padding-right: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover{
|
||||
|
||||
Reference in New Issue
Block a user