index.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. import { Helmet } from 'react-helmet';
  15. const messages = defineMessages({
  16. refresh: { id: 'refresh', defaultMessage: 'Refresh' },
  17. });
  18. const mapStateToProps = (state, props) => ({
  19. accountIds: state.getIn(['user_lists', 'reblogged_by', props.params.statusId]),
  20. });
  21. export default @connect(mapStateToProps)
  22. @injectIntl
  23. class Reblogs extends ImmutablePureComponent {
  24. static propTypes = {
  25. params: PropTypes.object.isRequired,
  26. dispatch: PropTypes.func.isRequired,
  27. accountIds: ImmutablePropTypes.list,
  28. multiColumn: PropTypes.bool,
  29. intl: PropTypes.object.isRequired,
  30. };
  31. componentWillMount () {
  32. if (!this.props.accountIds) {
  33. this.props.dispatch(fetchReblogs(this.props.params.statusId));
  34. }
  35. }
  36. componentWillReceiveProps(nextProps) {
  37. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  38. this.props.dispatch(fetchReblogs(nextProps.params.statusId));
  39. }
  40. }
  41. handleRefresh = () => {
  42. this.props.dispatch(fetchReblogs(this.props.params.statusId));
  43. }
  44. render () {
  45. const { intl, accountIds, multiColumn } = this.props;
  46. if (!accountIds) {
  47. return (
  48. <Column>
  49. <LoadingIndicator />
  50. </Column>
  51. );
  52. }
  53. const emptyMessage = <FormattedMessage id='status.reblogs.empty' defaultMessage='No one has boosted this post yet. When someone does, they will show up here.' />;
  54. return (
  55. <Column bindToDocument={!multiColumn}>
  56. <ColumnHeader
  57. showBackButton
  58. multiColumn={multiColumn}
  59. extraButton={(
  60. <button className='column-header__button' title={intl.formatMessage(messages.refresh)} aria-label={intl.formatMessage(messages.refresh)} onClick={this.handleRefresh}><Icon id='refresh' /></button>
  61. )}
  62. />
  63. <ScrollableList
  64. scrollKey='reblogs'
  65. emptyMessage={emptyMessage}
  66. bindToDocument={!multiColumn}
  67. >
  68. {accountIds.map(id =>
  69. <AccountContainer key={id} id={id} withNote={false} />,
  70. )}
  71. </ScrollableList>
  72. <Helmet>
  73. <meta name='robots' content='noindex' />
  74. </Helmet>
  75. </Column>
  76. );
  77. }
  78. }