import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import SidebarToggleButton from '../../components/SidebarToggleButton' import GridSlider from '../../components/GridSlider' import ArtistSentence from '../../components/ArtistSentence' import TrackList from '../../components/TrackList' import Parallax from '../../components/Parallax' import AutocompleteField from '../../components/AutocompleteField' import * as helpers from '../../helpers' import * as spotifyActions from '../../services/spotify/actions' class Discover extends React.Component{ constructor(props) { super(props) this._autocomplete_timer = false this.state = { seeds: [ { uri: 'spotify:genre:chill', name: 'Chill' } ], add_seed: '', adding_seed: false } } componentDidMount(){ if (this.props.authorized){ this.props.spotifyActions.getFavorites() } else { this.getRecommendations() } } componentWillReceiveProps(newProps, newState){ if (this.props.favorite_artists.length <= 0 && newProps.favorite_artists.length){ var initial_seeds = newProps.favorite_artists.sort(() => .5 - Math.random()) initial_seeds = initial_seeds.slice(0,2) this.setState({seeds: initial_seeds}) this.getRecommendations(initial_seeds) } } getRecommendations(seeds = this.state.seeds){ var uris = helpers.asURIs(seeds) this.props.spotifyActions.getRecommendations(uris) } removeSeed(index){ var seeds = this.state.seeds seeds.splice(index,1) this.setState({seeds: seeds}) this.getRecommendations(seeds) } handleSelect(e,item){ var seeds = this.state.seeds seeds.push(item) this.setState({seeds: seeds}) this.getRecommendations(seeds) } renderSeeds(){ return (