import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { Link, hashHistory } from 'react-router' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import ReactGA from 'react-ga' import Header from '../components/Header' import DropdownField from '../components/DropdownField' 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 SearchForm from '../components/SearchForm' import * as helpers from '../helpers' import * as coreActions from '../services/core/actions' 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(){ // Make sure we have search parameters to start with if (this.props.params && this.props.params.query){ this.props.coreActions.startSearch(this.props.view, this.props.params.query) } // Auto-focus on the input field $(document).find('.search-form input').focus(); } componentWillReceiveProps(newProps){ // Make sure we have some search parameters if (newProps.params && newProps.view && newProps.params.query){ if (this.props.params.query != newProps.params.query || this.props.view != newProps.view){ this.props.coreActions.startSearch(newProps.view, newProps.params.query) } // mopidy comes online if (!this.props.mopidy_connected && newProps.mopidy_connected){ this.props.coreActions.startSearch(newProps.view, newProps.params.query, true) } } } loadMore(type){ this.props.spotifyActions.getURL( this.props['spotify_'+type+'_more'], 'SPOTIFY_SEARCH_RESULTS_LOADED_MORE_'+type.toUpperCase()); } renderResults(){ var spotify_search_enabled = (this.props.search_settings && this.props.search_settings.spotify) var artists = [] if (this.props.spotify_search_results.artists){ artists = [...artists, ...helpers.getIndexedRecords(this.props.artists,this.props.spotify_search_results.artists)] } if (this.props.mopidy_search_results.artists){ artists = [...artists, ...helpers.getIndexedRecords(this.props.artists,this.props.mopidy_search_results.artists)] } var albums = [] if (this.props.spotify_search_results.albums){ albums = [...albums, ...helpers.getIndexedRecords(this.props.albums,this.props.spotify_search_results.albums)] } if (this.props.mopidy_search_results.albums){ albums = [...albums, ...helpers.getIndexedRecords(this.props.albums,this.props.mopidy_search_results.albums)] } var playlists = [] if (this.props.spotify_search_results.playlists){ playlists = [...playlists, ...helpers.getIndexedRecords(this.props.playlists,this.props.spotify_search_results.playlists)] } if (this.props.mopidy_search_results.playlists){ playlists = [...playlists, ...helpers.getIndexedRecords(this.props.playlists,this.props.mopidy_search_results.playlists)] } var tracks = [] if (this.props.spotify_search_results.tracks){ tracks = [...tracks, ...this.props.spotify_search_results.tracks] } if (this.props.mopidy_search_results.tracks){ tracks = [...tracks, ...this.props.mopidy_search_results.tracks] } switch (this.props.view){ case 'artists': return (