From 087b9938924b0f1f2e3fd81a3eb6e9cde0c3a074 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 4 Nov 2016 13:39:24 +0100 Subject: Adding list of who favourited status --- .../components/actions/interactions.jsx | 34 ++++++++++++ .../javascripts/components/containers/mastodon.jsx | 5 ++ .../components/features/favourites/index.jsx | 61 ++++++++++++++++++++++ .../features/status/components/detailed_status.jsx | 2 +- 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/components/features/favourites/index.jsx (limited to 'app/assets') diff --git a/app/assets/javascripts/components/actions/interactions.jsx b/app/assets/javascripts/components/actions/interactions.jsx index 5b13fd02e..45f4508f6 100644 --- a/app/assets/javascripts/components/actions/interactions.jsx +++ b/app/assets/javascripts/components/actions/interactions.jsx @@ -199,3 +199,37 @@ export function fetchReblogsFail(id, error) { error }; }; + +export function fetchFavourites(id) { + return (dispatch, getState) => { + dispatch(fetchFavouritesRequest(id)); + + api(getState).get(`/api/v1/statuses/${id}/favourited_by`).then(response => { + dispatch(fetchFavouritesSuccess(id, response.data)); + }).catch(error => { + dispatch(fetchFavouritesFail(id, error)); + }); + }; +}; + +export function fetchFavouritesRequest(id) { + return { + type: FAVOURITES_FETCH_REQUEST, + id + }; +}; + +export function fetchFavouritesSuccess(id, accounts) { + return { + type: FAVOURITES_FETCH_SUCCESS, + id, + accounts + }; +}; + +export function fetchFavouritesFail(id, error) { + return { + type: FAVOURITES_FETCH_FAIL, + error + }; +}; diff --git a/app/assets/javascripts/components/containers/mastodon.jsx b/app/assets/javascripts/components/containers/mastodon.jsx index a6c52f2a7..bf92e248d 100644 --- a/app/assets/javascripts/components/containers/mastodon.jsx +++ b/app/assets/javascripts/components/containers/mastodon.jsx @@ -29,6 +29,7 @@ import Compose from '../features/compose'; import Followers from '../features/followers'; import Following from '../features/following'; import Reblogs from '../features/reblogs'; +import Favourites from '../features/favourites'; const store = configureStore(); @@ -80,11 +81,15 @@ const Mastodon = React.createClass({ + + + + diff --git a/app/assets/javascripts/components/features/favourites/index.jsx b/app/assets/javascripts/components/features/favourites/index.jsx new file mode 100644 index 000000000..8f15bcad9 --- /dev/null +++ b/app/assets/javascripts/components/features/favourites/index.jsx @@ -0,0 +1,61 @@ +import { connect } from 'react-redux'; +import PureRenderMixin from 'react-addons-pure-render-mixin'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import LoadingIndicator from '../../components/loading_indicator'; +import { fetchFavourites } from '../../actions/interactions'; +import { ScrollContainer } from 'react-router-scroll'; +import AccountContainer from '../followers/containers/account_container'; +import Column from '../ui/components/column'; +import ColumnBackButton from '../../components/column_back_button'; + +const mapStateToProps = (state, props) => ({ + accountIds: state.getIn(['user_lists', 'favourited_by', Number(props.params.statusId)]) +}); + +const Favourites = React.createClass({ + + propTypes: { + params: React.PropTypes.object.isRequired, + dispatch: React.PropTypes.func.isRequired, + accountIds: ImmutablePropTypes.list + }, + + mixins: [PureRenderMixin], + + componentWillMount () { + this.props.dispatch(fetchFavourites(Number(this.props.params.statusId))); + }, + + componentWillReceiveProps(nextProps) { + if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) { + this.props.dispatch(fetchFavourites(Number(nextProps.params.statusId))); + } + }, + + render () { + const { accountIds } = this.props; + + if (!accountIds) { + return ( + + + + ); + } + + return ( + + + + +
+ {accountIds.map(id => )} +
+
+
+ ); + } + +}); + +export default connect(mapStateToProps)(Favourites); diff --git a/app/assets/javascripts/components/features/status/components/detailed_status.jsx b/app/assets/javascripts/components/features/status/components/detailed_status.jsx index bc8dbe63d..71335970f 100644 --- a/app/assets/javascripts/components/features/status/components/detailed_status.jsx +++ b/app/assets/javascripts/components/features/status/components/detailed_status.jsx @@ -54,7 +54,7 @@ const DetailedStatus = React.createClass({ {media}
- {moment(status.get('created_at')).format('HH:mm, DD MMM Y')} · {status.get('reblogs_count')} · {status.get('favourites_count')} + {moment(status.get('created_at')).format('HH:mm, DD MMM Y')} · {status.get('reblogs_count')} · {status.get('favourites_count')}
); -- cgit