index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import ImmutablePureComponent from 'react-immutable-pure-component';
  4. import PropTypes from 'prop-types';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import LoadingIndicator from '../../components/loading_indicator';
  7. import { fetchReblogs } from '../../actions/interactions';
  8. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  9. import AccountContainer from '../../containers/account_container';
  10. import Column from '../ui/components/column';
  11. import ScrollableList from '../../components/scrollable_list';
  12. import Icon from 'mastodon/components/icon';
  13. import ColumnHeader from '../../components/column_header';
  14. const messages = defineMessages({
  15. refresh: { id: 'refresh', defaultMessage: 'Refresh' },
  16. });
  17. const mapStateToProps = (state, props) => ({
  18. accountIds: state.getIn(['user_lists', 'reblogged_by', props.params.statusId]),
  19. });
  20. export default @connect(mapStateToProps)
  21. @injectIntl
  22. class Reblogs extends ImmutablePureComponent {
  23. static propTypes = {
  24. params: PropTypes.object.isRequired,
  25. dispatch: PropTypes.func.isRequired,
  26. accountIds: ImmutablePropTypes.list,
  27. multiColumn: PropTypes.bool,
  28. intl: PropTypes.object.isRequired,
  29. };
  30. componentWillMount () {
  31. if (!this.props.accountIds) {
  32. this.props.dispatch(fetchReblogs(this.props.params.statusId));
  33. }
  34. }
  35. componentWillReceiveProps(nextProps) {
  36. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  37. this.props.dispatch(fetchReblogs(nextProps.params.statusId));
  38. }
  39. }
  40. handleRefresh = () => {
  41. this.props.dispatch(fetchReblogs(this.props.params.statusId));
  42. }
  43. render () {
  44. const { intl, accountIds, multiColumn } = this.props;
  45. if (!accountIds) {
  46. return (
  47. <Column>
  48. <LoadingIndicator />
  49. </Column>
  50. );
  51. }
  52. const emptyMessage = <FormattedMessage id='status.reblogs.empty' defaultMessage='No one has boosted this post yet. When someone does, they will show up here.' />;
  53. return (
  54. <Column bindToDocument={!multiColumn}>
  55. <ColumnHeader
  56. showBackButton
  57. multiColumn={multiColumn}
  58. extraButton={(
  59. <button className='column-header__button' title={intl.formatMessage(messages.refresh)} aria-label={intl.formatMessage(messages.refresh)} onClick={this.handleRefresh}><Icon id='refresh' /></button>
  60. )}
  61. />
  62. <ScrollableList
  63. scrollKey='reblogs'
  64. emptyMessage={emptyMessage}
  65. bindToDocument={!multiColumn}
  66. >
  67. {accountIds.map(id =>
  68. <AccountContainer key={id} id={id} withNote={false} />,
  69. )}
  70. </ScrollableList>
  71. </Column>
  72. );
  73. }
  74. }