Unreblogging and unfavouriting from the UI

This commit is contained in:
Eugen Rochko 2016-10-02 15:14:26 +02:00
parent 4909bbf415
commit 1fce687f8e
6 changed files with 119 additions and 25 deletions

View File

@ -8,6 +8,14 @@ export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS'; export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
export const FAVOURITE_FAIL = 'FAVOURITE_FAIL'; 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) { export function reblog(status) {
return function (dispatch, getState) { return function (dispatch, getState) {
dispatch(reblogRequest(status)); dispatch(reblogRequest(status));
@ -24,10 +32,12 @@ export function reblog(status) {
export function unreblog(status) { export function unreblog(status) {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch(unreblogRequest(status));
api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => { api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
// dispatch(unreblogSuccess(status, response.data));
}).catch(error => { }).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) { export function favourite(status) {
return function (dispatch, getState) { return function (dispatch, getState) {
dispatch(favouriteRequest(status)); dispatch(favouriteRequest(status));
@ -69,10 +102,12 @@ export function favourite(status) {
export function unfavourite(status) { export function unfavourite(status) {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch(unfavouriteRequest(status));
api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => { api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
// dispatch(unfavouriteSuccess(status, response.data));
}).catch(error => { }).catch(error => {
// dispatch(unfavouriteFail(status, error));
}); });
}; };
}; };
@ -99,3 +134,26 @@ export function favouriteFail(status, error) {
error: 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
};
};

View File

@ -7,25 +7,24 @@ const ActionBar = React.createClass({
propTypes: { propTypes: {
account: ImmutablePropTypes.map.isRequired, account: ImmutablePropTypes.map.isRequired,
me: React.PropTypes.number.isRequired, me: React.PropTypes.number.isRequired,
onFollow: React.PropTypes.func.isRequired, onFollow: React.PropTypes.func.isRequired
onUnfollow: React.PropTypes.func.isRequired
}, },
mixins: [PureRenderMixin], mixins: [PureRenderMixin],
render () { render () {
const { account, me } = this.props; const { account, me } = this.props;
let infoText = ''; let infoText = '';
let actionButton = ''; let buttonText = '';
if (account.get('id') === me) { if (account.get('id') === me) {
infoText = 'This is you!'; buttonText = 'This is you!';
} else { } else {
if (account.getIn(['relationship', 'following'])) { if (account.getIn(['relationship', 'following'])) {
actionButton = <Button text='Unfollow' onClick={this.props.onUnfollow} /> buttonText = 'Unfollow';
} else { } else {
actionButton = <Button text='Follow' onClick={this.props.onFollow} /> buttonText = 'Follow';
} }
if (account.getIn(['relationship', 'followed_by'])) { if (account.getIn(['relationship', 'followed_by'])) {
@ -35,7 +34,7 @@ const ActionBar = React.createClass({
return ( return (
<div style={{ borderTop: '1px solid #363c4b', borderBottom: '1px solid #363c4b', padding: '10px', lineHeight: '36px', overflow: 'hidden', flex: '0 0 auto' }}> <div style={{ borderTop: '1px solid #363c4b', borderBottom: '1px solid #363c4b', padding: '10px', lineHeight: '36px', overflow: 'hidden', flex: '0 0 auto' }}>
{actionButton} <span style={{ color: '#616b86', fontWeight: '500', textTransform: 'uppercase', float: 'right', display: 'block' }}>{infoText}</span> <Button text={buttonText} onClick={this.props.onFollow} disabled={account.get('id') === me} /> <span style={{ color: '#616b86', fontWeight: '500', textTransform: 'uppercase', float: 'right', display: 'block' }}>{infoText}</span>
</div> </div>
); );
}, },

View File

@ -10,7 +10,12 @@ import {
} from '../../actions/accounts'; } from '../../actions/accounts';
import { deleteStatus } from '../../actions/statuses'; import { deleteStatus } from '../../actions/statuses';
import { replyCompose } from '../../actions/compose'; import { replyCompose } from '../../actions/compose';
import { favourite, reblog } from '../../actions/interactions'; import {
favourite,
reblog,
unreblog,
unfavourite
} from '../../actions/interactions';
import Header from './components/header'; import Header from './components/header';
import { import {
selectStatus, selectStatus,
@ -54,11 +59,11 @@ const Account = React.createClass({
}, },
handleFollow () { handleFollow () {
this.props.dispatch(followAccount(this.props.account.get('id'))); if (this.props.account.getIn(['relationship', 'following'])) {
}, this.props.dispatch(unfollowAccount(this.props.account.get('id')));
} else {
handleUnfollow () { this.props.dispatch(followAccount(this.props.account.get('id')));
this.props.dispatch(unfollowAccount(this.props.account.get('id'))); }
}, },
handleReply (status) { handleReply (status) {
@ -66,11 +71,19 @@ const Account = React.createClass({
}, },
handleReblog (status) { handleReblog (status) {
this.props.dispatch(reblog(status)); if (status.get('reblogged')) {
this.props.dispatch(unreblog(status));
} else {
this.props.dispatch(reblog(status));
}
}, },
handleFavourite (status) { handleFavourite (status) {
this.props.dispatch(favourite(status)); if (status.get('favourited')) {
this.props.dispatch(unfavourite(status));
} else {
this.props.dispatch(favourite(status));
}
}, },
handleDelete (status) { handleDelete (status) {

View File

@ -1,7 +1,12 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import StatusList from '../../../components/status_list'; import StatusList from '../../../components/status_list';
import { replyCompose } from '../../../actions/compose'; import { replyCompose } from '../../../actions/compose';
import { reblog, favourite } from '../../../actions/interactions'; import {
reblog,
favourite,
unreblog,
unfavourite
} from '../../../actions/interactions';
import { expandTimeline } from '../../../actions/timelines'; import { expandTimeline } from '../../../actions/timelines';
import { selectStatus } from '../../../reducers/timelines'; import { selectStatus } from '../../../reducers/timelines';
import { deleteStatus } from '../../../actions/statuses'; import { deleteStatus } from '../../../actions/statuses';
@ -20,11 +25,19 @@ const mapDispatchToProps = function (dispatch, props) {
}, },
onFavourite (status) { onFavourite (status) {
dispatch(favourite(status)); if (status.get('favourited')) {
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
}, },
onReblog (status) { onReblog (status) {
dispatch(reblog(status)); if (status.get('reblogged')) {
dispatch(unreblog(status));
} else {
dispatch(reblog(status));
}
}, },
onScrollToBottom () { onScrollToBottom () {

View File

@ -1,6 +1,11 @@
import { COMPOSE_SUBMIT_FAIL, COMPOSE_UPLOAD_FAIL } from '../actions/compose'; import { COMPOSE_SUBMIT_FAIL, COMPOSE_UPLOAD_FAIL } from '../actions/compose';
import { FOLLOW_SUBMIT_FAIL } from '../actions/follow'; import { FOLLOW_SUBMIT_FAIL } from '../actions/follow';
import { REBLOG_FAIL, FAVOURITE_FAIL } from '../actions/interactions'; import {
REBLOG_FAIL,
UNREBLOG_FAIL,
FAVOURITE_FAIL,
UNFAVOURITE_FAIL
} from '../actions/interactions';
import { import {
TIMELINE_REFRESH_FAIL, TIMELINE_REFRESH_FAIL,
TIMELINE_EXPAND_FAIL TIMELINE_EXPAND_FAIL
@ -55,6 +60,8 @@ export default function notifications(state = initialState, action) {
case ACCOUNT_TIMELINE_EXPAND_FAIL: case ACCOUNT_TIMELINE_EXPAND_FAIL:
case STATUS_FETCH_FAIL: case STATUS_FETCH_FAIL:
case STATUS_DELETE_FAIL: case STATUS_DELETE_FAIL:
case UNREBLOG_FAIL:
case UNFAVOURITE_FAIL:
return notificationFromError(state, action.error); return notificationFromError(state, action.error);
case NOTIFICATION_DISMISS: case NOTIFICATION_DISMISS:
return state.filterNot(item => item.get('key') === action.notification.key); return state.filterNot(item => item.get('key') === action.notification.key);

View File

@ -6,7 +6,9 @@ import {
} from '../actions/timelines'; } from '../actions/timelines';
import { import {
REBLOG_SUCCESS, REBLOG_SUCCESS,
FAVOURITE_SUCCESS UNREBLOG_SUCCESS,
FAVOURITE_SUCCESS,
UNFAVOURITE_SUCCESS
} from '../actions/interactions'; } from '../actions/interactions';
import { import {
ACCOUNT_SET_SELF, ACCOUNT_SET_SELF,
@ -219,6 +221,8 @@ export default function timelines(state = initialState, action) {
return deleteStatus(state, action.id); return deleteStatus(state, action.id);
case REBLOG_SUCCESS: case REBLOG_SUCCESS:
case FAVOURITE_SUCCESS: case FAVOURITE_SUCCESS:
case UNREBLOG_SUCCESS:
case UNFAVOURITE_SUCCESS:
return normalizeStatus(state, Immutable.fromJS(action.response)); return normalizeStatus(state, Immutable.fromJS(action.response));
case ACCOUNT_SET_SELF: case ACCOUNT_SET_SELF:
return setSelf(state, Immutable.fromJS(action.account)); return setSelf(state, Immutable.fromJS(action.account));