diff --git a/app/assets/javascripts/components/actions/interactions.jsx b/app/assets/javascripts/components/actions/interactions.jsx index ce7797eaab..b3569d0b31 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 3a04ebb094..a6c52f2a7a 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 0000000000..bec08f1eee --- /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 9f8e9b6cc2..bc8dbe63d2 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 f011447864..ba66f182ac 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 d3b073e954..686179af20 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; }