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 ReactGA from 'react-ga' 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){ // new query if( this.props.params.query != newProps.params.query ){ this.performSearch( newProps ) } // mopidy comes online if( !this.props.mopidy_connected && newProps.mopidy_connected ){ this.props.mopidyActions.getSearchResults( newProps.params.query, newProps.uri_schemes ) } } performSearch( props = this.props ){ this.props.uiActions.searchStarted( props.params.query ) this.props.spotifyActions.getSearchResults( props.params.query ) this.props.mopidyActions.getSearchResults( props.params.query, props.uri_schemes ) } loadMore(type){ if( !this.props.search_results[type] || !this.props.search_results[type+'_more'] ){ return } this.props.spotifyActions.getURL( this.props.search_results[type+'_more'], 'SPOTIFY_SEARCH_RESULTS_LOADED_MORE_'+ type.toUpperCase() ); } renderResults(){ switch( this.props.params.type ){ case 'artists': return (
this.loadMore('artists') }/>
) break case 'albums': return (
this.loadMore('albums') }/>
) break case 'playlists': return (
this.loadMore('playlists') }/>
) break case 'tracks': return (
this.loadMore('tracks') }/>
) break default: return (

Artists

Albums

Playlists

Tracks

this.loadMore('tracks') }/>
) } } render(){ return (
{ this.renderResults() }
); } } const mapStateToProps = (state, ownProps) => { return { mopidy_connected: state.mopidy.connected, uri_schemes: state.mopidy.uri_schemes, search_results: state.ui.search_results } } const mapDispatchToProps = (dispatch) => { return { uiActions: bindActionCreators(uiActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Search)