From 992c65686485b4a853fbe84053419bfa548bb611 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Mon, 12 Apr 2021 21:12:54 +1200 Subject: [PATCH] Follow button to functional component --- src/js/components/Fields/FollowButton.js | 102 ++++++++++------------- 1 file changed, 46 insertions(+), 56 deletions(-) diff --git a/src/js/components/Fields/FollowButton.js b/src/js/components/Fields/FollowButton.js index 927e57ef..519d77b0 100755 --- a/src/js/components/Fields/FollowButton.js +++ b/src/js/components/Fields/FollowButton.js @@ -3,76 +3,66 @@ import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import * as uiActions from '../../services/ui/actions'; import * as spotifyActions from '../../services/spotify/actions'; -import { isLoading, getFromUri } from '../../util/helpers'; +import { getFromUri } from '../../util/helpers'; import { i18n } from '../../locale'; import { Button } from '../Button'; import { makeLoadingSelector } from '../../util/selectors'; -class FollowButton extends React.Component { - remove = () => { - const { spotifyActions: actions, uri } = this.props; - actions.following(uri, 'DELETE'); - } +const FollowButton = ({ + spotifyActions: { + following, + }, + uiActions: { + createNotification, + }, + uri, + addText, + removeText, + spotify_authorized, + is_following, + loading, +}) => { + const remove = () => following(uri, 'DELETE'); + const add = () => following(uri, 'PUT'); + const unauthorized = () => createNotification({ + content: i18n('errors.authorization_required', { provider: i18n('services.spotify.title') }), + level: 'warning', + }); - add = () => { - const { spotifyActions: actions, uri } = this.props; - actions.following(uri, 'PUT'); - } + if (!uri) return null; - unauthorized = () => { - const { uiActions: { createNotification } } = this.props; - - createNotification({ - content: i18n('errors.authorization_required', { provider: i18n('services.spotify.title') }), - level: 'warning', - }); - } - - render = () => { - const { - uri, - addText, - removeText, - spotify_authorized, - is_following, - loading, - } = this.props; - - if (!uri) return null; - - if (!spotify_authorized) { - return ( - - ); - } if (is_following === true) { - return ( - - ); - } + if (!spotify_authorized) { return ( ); + } if (is_following === true) { + return ( + + ); } + return ( + + ); } const mapStateToProps = (state, ownProps) => {