import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { Link } from 'react-router' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import Header from '../components/Header' import TrackList from '../components/TrackList' import ArtistGrid from '../components/ArtistGrid' import AlbumGrid from '../components/AlbumGrid' import PlaylistGrid from '../components/PlaylistGrid' import LazyLoadListener from '../components/LazyLoadListener' import * as uiActions from '../services/ui/actions' import * as mopidyActions from '../services/mopidy/actions' import * as spotifyActions from '../services/spotify/actions' class Search extends React.Component{ constructor(props) { super(props); } componentDidMount(){ this.performSearch() } componentWillReceiveProps(newProps){ if( this.props.params.query != newProps.params.query || !this.props.mopidy.connected && newProps.mopidy.connected ){ this.performSearch( newProps ) } } performSearch( props = this.props ){ this.props.spotifyActions.getSearchResults( props.params.query ) if( props.mopidy.connected ){ this.props.mopidyActions.getSearchResults( props.params.query, props.mopidy.uri_schemes ) } } loadMore(type){ if( !this.props.spotify['search_results_'+type] || !this.props.spotify['search_results_'+type].next ){ return } this.props.spotifyActions.getURL( this.props.spotify['search_results_'+type].next, 'SPOTIFY_SEARCH_RESULTS_LOADED_MORE_'+ type.toUpperCase() ); } compiledResults(type){ var results = []; // merge our mopidy results in if( this.props.mopidy['search_results_'+type] ){ results = [...results, ...this.props.mopidy['search_results_'+type]] } // merge our spotify results in if( this.props.spotify['search_results_'+type] && this.props.spotify['search_results_'+type].items ){ results = [...results, ...this.props.spotify['search_results_'+type].items] } return results; } renderResults(){ switch( this.props.params.type ){ case 'artists': return (