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

57 lines
1.5 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
2017-02-07 20:07:04 +13:00
var className = ''
2017-02-07 10:00:29 +13:00
if (this.props.className) className += ' '+this.props.className
if( this.props.is_following === true ){
2017-02-12 21:11:50 +13:00
return <button className={className+' destructive'} onClick={ () => this.remove() }>{ this.props.removeText }</button>
2016-11-18 13:21:30 +13:00
}else{
2017-02-07 10:00:29 +13:00
return <button className={className} onClick={ () => this.add() }>{ this.props.addText }</button>
2016-11-18 13:21:30 +13:00
}
}
}
const mapStateToProps = (state, ownProps) => {
return {
spotify_authorized: state.spotify.authorized
2016-11-18 13:21:30 +13:00
}
}
const mapDispatchToProps = (dispatch) => {
return {
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(FollowButton)