Files
Iris/src/js/components/FollowButton.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-11-18 13:21:30 +13:00
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router'
import { createStore, bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'
import * as helpers from '../helpers'
import * as spotifyActions from '../services/spotify/actions'
class FollowButton extends React.Component{
constructor(props) {
super(props);
}
componentDidMount(){
if( this.props.spotify_authorized && this.props.uri ){
this.props.spotifyActions.following(this.props.uri)
}
2016-11-18 13:21:30 +13:00
}
remove(){
this.props.spotifyActions.following(this.props.uri, 'DELETE')
}
add(){
this.props.spotifyActions.following(this.props.uri, 'PUT')
}
render(){
if( !this.props.spotify_authorized || !this.props.uri ) return false
var item = {}
switch (helpers.uriType( this.props.uri )){
case 'artist':
item = this.props.artists[this.props.uri]
break
case 'user':
item = this.props.users[this.props.uri]
break
case 'album':
item = this.props.albums[this.props.uri]
break
case 'playlist':
item = this.props.playlists[this.props.uri]
break
}
2016-11-18 13:21:30 +13:00
if( item.following === true ){
return <button className="tertiary large" onClick={ () => this.remove() }>{ this.props.removeText }</button>
}else{
return <button className="tertiary large" onClick={ () => this.add() }>{ this.props.addText }</button>
}
}
}
const mapStateToProps = (state, ownProps) => {
return {
spotify_authorized: state.spotify.authorized,
artists: state.ui.artists,
users: state.ui.users,
albums: state.ui.albums,
playlists: state.ui.playlists
2016-11-18 13:21:30 +13:00
}
}
const mapDispatchToProps = (dispatch) => {
return {
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(FollowButton)