From 1fce687f8e03d78b4b842422fc6621bba439e1cd Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 2 Oct 2016 15:14:26 +0200 Subject: [PATCH] Unreblogging and unfavouriting from the UI --- .../components/actions/interactions.jsx | 66 +++++++++++++++++-- .../account/components/action_bar.jsx | 15 ++--- .../components/features/account/index.jsx | 29 +++++--- .../ui/containers/status_list_container.jsx | 19 +++++- .../components/reducers/notifications.jsx | 9 ++- .../components/reducers/timelines.jsx | 6 +- 6 files changed, 119 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/components/actions/interactions.jsx b/app/assets/javascripts/components/actions/interactions.jsx index 8ce0c7561a..ce7797eaab 100644 --- a/app/assets/javascripts/components/actions/interactions.jsx +++ b/app/assets/javascripts/components/actions/interactions.jsx @@ -8,6 +8,14 @@ export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST'; export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS'; export const FAVOURITE_FAIL = 'FAVOURITE_FAIL'; +export const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST'; +export const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS'; +export const UNREBLOG_FAIL = 'UNREBLOG_FAIL'; + +export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST'; +export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS'; +export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL'; + export function reblog(status) { return function (dispatch, getState) { dispatch(reblogRequest(status)); @@ -24,10 +32,12 @@ export function reblog(status) { export function unreblog(status) { return (dispatch, getState) => { + dispatch(unreblogRequest(status)); + api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => { - // + dispatch(unreblogSuccess(status, response.data)); }).catch(error => { - // + dispatch(unreblogFail(status, error)); }); }; }; @@ -55,6 +65,29 @@ export function reblogFail(status, error) { }; }; +export function unreblogRequest(status) { + return { + type: UNREBLOG_REQUEST, + status: status + }; +}; + +export function unreblogSuccess(status, response) { + return { + type: UNREBLOG_SUCCESS, + status: status, + response: response + }; +}; + +export function unreblogFail(status, error) { + return { + type: UNREBLOG_FAIL, + status: status, + error: error + }; +}; + export function favourite(status) { return function (dispatch, getState) { dispatch(favouriteRequest(status)); @@ -69,10 +102,12 @@ export function favourite(status) { export function unfavourite(status) { return (dispatch, getState) => { + dispatch(unfavouriteRequest(status)); + api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => { - // + dispatch(unfavouriteSuccess(status, response.data)); }).catch(error => { - // + dispatch(unfavouriteFail(status, error)); }); }; }; @@ -99,3 +134,26 @@ export function favouriteFail(status, error) { error: error }; }; + +export function unfavouriteRequest(status) { + return { + type: UNFAVOURITE_REQUEST, + status: status + }; +}; + +export function unfavouriteSuccess(status, response) { + return { + type: UNFAVOURITE_SUCCESS, + status: status, + response: response + }; +}; + +export function unfavouriteFail(status, error) { + return { + type: UNFAVOURITE_FAIL, + status: status, + error: error + }; +}; diff --git a/app/assets/javascripts/components/features/account/components/action_bar.jsx b/app/assets/javascripts/components/features/account/components/action_bar.jsx index aa37d9238a..309471dd22 100644 --- a/app/assets/javascripts/components/features/account/components/action_bar.jsx +++ b/app/assets/javascripts/components/features/account/components/action_bar.jsx @@ -7,25 +7,24 @@ const ActionBar = React.createClass({ propTypes: { account: ImmutablePropTypes.map.isRequired, me: React.PropTypes.number.isRequired, - onFollow: React.PropTypes.func.isRequired, - onUnfollow: React.PropTypes.func.isRequired + onFollow: React.PropTypes.func.isRequired }, mixins: [PureRenderMixin], render () { const { account, me } = this.props; - + let infoText = ''; - let actionButton = ''; + let buttonText = ''; if (account.get('id') === me) { - infoText = 'This is you!'; + buttonText = 'This is you!'; } else { if (account.getIn(['relationship', 'following'])) { - actionButton =