From 6d26bfd14706872f6e4d1c3a3e45b00d81cf86cb Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 3 Nov 2016 20:16:14 +0100 Subject: [PATCH] Add list of who reblogged status --- .../components/actions/interactions.jsx | 38 ++++++++++++ .../components/containers/mastodon.jsx | 2 + .../components/features/reblogs/index.jsx | 61 +++++++++++++++++++ .../status/components/detailed_status.jsx | 3 +- .../components/reducers/accounts.jsx | 4 +- .../components/reducers/user_lists.jsx | 3 + 6 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/components/features/reblogs/index.jsx diff --git a/app/assets/javascripts/components/actions/interactions.jsx b/app/assets/javascripts/components/actions/interactions.jsx index ce7797ea..b3569d0b 100644 --- a/app/assets/javascripts/components/actions/interactions.jsx +++ b/app/assets/javascripts/components/actions/interactions.jsx @@ -16,6 +16,10 @@ export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST'; export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS'; export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL'; +export const REBLOGS_FETCH_REQUEST = 'REBLOGS_FETCH_REQUEST'; +export const REBLOGS_FETCH_SUCCESS = 'REBLOGS_FETCH_SUCCESS'; +export const REBLOGS_FETCH_FAIL = 'REBLOGS_FETCH_FAIL'; + export function reblog(status) { return function (dispatch, getState) { dispatch(reblogRequest(status)); @@ -157,3 +161,37 @@ export function unfavouriteFail(status, error) { error: error }; }; + +export function fetchReblogs(id) { + return (dispatch, getState) => { + dispatch(fetchReblogsRequest(id)); + + api(getState).get(`/api/v1/statuses/${id}/reblogged_by`).then(response => { + dispatch(fetchReblogsSuccess(id, response.data)); + }).catch(error => { + dispatch(fetchReblogsFail(id, error)); + }); + }; +}; + +export function fetchReblogsRequest(id) { + return { + type: REBLOGS_FETCH_REQUEST, + id + }; +}; + +export function fetchReblogsSuccess(id, accounts) { + return { + type: REBLOGS_FETCH_SUCCESS, + id, + accounts + }; +}; + +export function fetchReblogsFail(id, error) { + return { + type: REBLOGS_FETCH_FAIL, + error + }; +}; diff --git a/app/assets/javascripts/components/containers/mastodon.jsx b/app/assets/javascripts/components/containers/mastodon.jsx index 3a04ebb0..a6c52f2a 100644 --- a/app/assets/javascripts/components/containers/mastodon.jsx +++ b/app/assets/javascripts/components/containers/mastodon.jsx @@ -28,6 +28,7 @@ import MentionsTimeline from '../features/mentions_timeline'; import Compose from '../features/compose'; import Followers from '../features/followers'; import Following from '../features/following'; +import Reblogs from '../features/reblogs'; const store = configureStore(); @@ -83,6 +84,7 @@ const Mastodon = React.createClass({ + diff --git a/app/assets/javascripts/components/features/reblogs/index.jsx b/app/assets/javascripts/components/features/reblogs/index.jsx new file mode 100644 index 00000000..bec08f1e --- /dev/null +++ b/app/assets/javascripts/components/features/reblogs/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 { fetchReblogs } 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', 'reblogged_by', Number(props.params.statusId)]) +}); + +const Reblogs = React.createClass({ + + propTypes: { + params: React.PropTypes.object.isRequired, + dispatch: React.PropTypes.func.isRequired, + accountIds: ImmutablePropTypes.list + }, + + mixins: [PureRenderMixin], + + componentWillMount () { + this.props.dispatch(fetchReblogs(Number(this.props.params.statusId))); + }, + + componentWillReceiveProps(nextProps) { + if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) { + this.props.dispatch(fetchReblogs(Number(nextProps.params.statusId))); + } + }, + + render () { + const { accountIds } = this.props; + + if (!accountIds) { + return ( + + + + ); + } + + return ( + + + + +
+ {accountIds.map(id => )} +
+
+
+ ); + } + +}); + +export default connect(mapStateToProps)(Reblogs); 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 9f8e9b6c..bc8dbe63 100644 --- a/app/assets/javascripts/components/features/status/components/detailed_status.jsx +++ b/app/assets/javascripts/components/features/status/components/detailed_status.jsx @@ -6,6 +6,7 @@ import StatusContent from '../../../components/status_content'; import MediaGallery from '../../../components/media_gallery'; import VideoPlayer from '../../../components/video_player'; import moment from 'moment'; +import { Link } from 'react-router'; const DetailedStatus = React.createClass({ @@ -53,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')}
); diff --git a/app/assets/javascripts/components/reducers/accounts.jsx b/app/assets/javascripts/components/reducers/accounts.jsx index f0114478..ba66f182 100644 --- a/app/assets/javascripts/components/reducers/accounts.jsx +++ b/app/assets/javascripts/components/reducers/accounts.jsx @@ -12,7 +12,8 @@ import { REBLOG_SUCCESS, UNREBLOG_SUCCESS, FAVOURITE_SUCCESS, - UNFAVOURITE_SUCCESS + UNFAVOURITE_SUCCESS, + REBLOGS_FETCH_SUCCESS } from '../actions/interactions'; import { TIMELINE_REFRESH_SUCCESS, @@ -64,6 +65,7 @@ export default function accounts(state = initialState, action) { case SUGGESTIONS_FETCH_SUCCESS: case FOLLOWERS_FETCH_SUCCESS: case FOLLOWING_FETCH_SUCCESS: + case REBLOGS_FETCH_SUCCESS: return normalizeAccounts(state, action.accounts); case TIMELINE_REFRESH_SUCCESS: case TIMELINE_EXPAND_SUCCESS: diff --git a/app/assets/javascripts/components/reducers/user_lists.jsx b/app/assets/javascripts/components/reducers/user_lists.jsx index d3b073e9..686179af 100644 --- a/app/assets/javascripts/components/reducers/user_lists.jsx +++ b/app/assets/javascripts/components/reducers/user_lists.jsx @@ -3,6 +3,7 @@ import { FOLLOWING_FETCH_SUCCESS } from '../actions/accounts'; import { SUGGESTIONS_FETCH_SUCCESS } from '../actions/suggestions'; +import { REBLOGS_FETCH_SUCCESS } from '../actions/interactions'; import Immutable from 'immutable'; const initialState = Immutable.Map({ @@ -19,6 +20,8 @@ export default function userLists(state = initialState, action) { return state.setIn(['following', action.id], Immutable.List(action.accounts.map(item => item.id))); case SUGGESTIONS_FETCH_SUCCESS: return state.set('suggestions', Immutable.List(action.accounts.map(item => item.id))); + case REBLOGS_FETCH_SUCCESS: + return state.setIn(['reblogged_by', action.id], Immutable.List(action.accounts.map(item => item.id))); default: return state; }