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 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.type && this.props.params.query){ this.props.uiActions.startSearch(this.props.params.type, 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.params.type && newProps.params.query){ if (this.props.params.query != newProps.params.query || this.props.params.type != newProps.params.type){ this.props.uiActions.startSearch(newProps.params.type, newProps.params.query) } // mopidy comes online if (!this.props.mopidy_connected && newProps.mopidy_connected){ this.props.uiActions.startSearch(newProps.params.type, newProps.params.query, true) } } } loadMore(type){ this.props.spotifyActions.getURL( this.props[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.artists_uris){ for (var i = 0; i < this.props.artists_uris.length; i++){ var uri = this.props.artists_uris[i] if (this.props.artists.hasOwnProperty(uri)){ artists.push(this.props.artists[uri]) } } } var albums = [] if (this.props.albums_uris){ for (var i = 0; i < this.props.albums_uris.length; i++){ var uri = this.props.albums_uris[i] if (this.props.albums.hasOwnProperty(uri)){ albums.push(this.props.albums[uri]) } } } var playlists = [] if (this.props.playlists_uris){ for (var i = 0; i < this.props.playlists_uris.length; i++){ var uri = this.props.playlists_uris[i] if (this.props.playlists.hasOwnProperty(uri)){ playlists.push(this.props.playlists[uri]) } } } var tracks = [] if (this.props.tracks){ for (var i = 0; i < this.props.tracks.length; i++){ if (helpers.uriSource(this.props.tracks[i].uri)){ tracks.push(this.props.tracks[i]) } } } switch (this.props.params.type){ case 'artists': return (