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

67 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 uiActions from '../services/ui/actions'
2016-11-18 13:21:30 +13:00
import * as spotifyActions from '../services/spotify/actions'
class FollowButton extends React.Component{
2017-10-10 13:05:28 +13:00
constructor(props){
super(props);
2016-11-18 13:21:30 +13:00
}
remove(){
this.props.spotifyActions.following(this.props.uri, 'DELETE');
2016-11-18 13:21:30 +13:00
}
add(){
this.props.spotifyActions.following(this.props.uri, 'PUT');
2016-11-18 13:21:30 +13:00
}
render(){
if (!this.props.uri){
return false;
2017-06-12 21:10:04 +12:00
}
2016-11-18 13:21:30 +13:00
var className = '';
2017-02-07 10:00:29 +13:00
2017-06-12 21:10:04 +12:00
// Inherit passed-down classes
if (this.props.className){
className += ' '+this.props.className;
2017-06-12 21:10:04 +12:00
}
// Loader
2017-06-14 20:21:02 +12:00
if (helpers.isLoading(this.props.load_queue,['/following','/followers','me/albums/contains/?ids=','me/albums/?ids='])){
className += ' working';
2017-06-12 21:10:04 +12:00
}
if (!this.props.spotify_authorized){
2017-11-04 14:03:59 +13:00
return <button className={className+' disabled'} onClick={e => this.props.uiActions.createNotification('You must authorize Spotify first','warning')}>{this.props.addText}</button>
} else if (this.props.is_following === true){
2017-06-12 21:10:04 +12:00
return <button className={className+' destructive'} onClick={e => this.remove()}>{this.props.removeText}</button>
} else {
return <button className={className} onClick={e => this.add()}>{this.props.addText}</button>
2016-11-18 13:21:30 +13:00
}
}
}
const mapStateToProps = (state, ownProps) => {
return {
2017-06-12 21:10:04 +12:00
load_queue: state.ui.load_queue,
spotify_authorized: state.spotify.authorization
2016-11-18 13:21:30 +13:00
}
}
const mapDispatchToProps = (dispatch) => {
return {
uiActions: bindActionCreators(uiActions, dispatch),
2016-11-18 13:21:30 +13:00
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(FollowButton)