You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.0 KiB

  1. import { debounce } from 'lodash';
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  7. import { connect } from 'react-redux';
  8. import ColumnHeader from 'mastodon/components/column_header';
  9. import ScrollableList from 'mastodon/components/scrollable_list';
  10. import Column from 'mastodon/features/ui/components/column';
  11. import { Helmet } from 'react-helmet';
  12. import Hashtag from 'mastodon/components/hashtag';
  13. import { expandFollowedHashtags, fetchFollowedHashtags } from 'mastodon/actions/tags';
  14. const messages = defineMessages({
  15. heading: { id: 'followed_tags', defaultMessage: 'Followed hashtags' },
  16. });
  17. const mapStateToProps = state => ({
  18. hashtags: state.getIn(['followed_tags', 'items']),
  19. isLoading: state.getIn(['followed_tags', 'isLoading'], true),
  20. hasMore: !!state.getIn(['followed_tags', 'next']),
  21. });
  22. class FollowedTags extends ImmutablePureComponent {
  23. static propTypes = {
  24. params: PropTypes.object.isRequired,
  25. dispatch: PropTypes.func.isRequired,
  26. intl: PropTypes.object.isRequired,
  27. hashtags: ImmutablePropTypes.list,
  28. isLoading: PropTypes.bool,
  29. hasMore: PropTypes.bool,
  30. multiColumn: PropTypes.bool,
  31. };
  32. componentDidMount() {
  33. this.props.dispatch(fetchFollowedHashtags());
  34. }
  35. handleLoadMore = debounce(() => {
  36. this.props.dispatch(expandFollowedHashtags());
  37. }, 300, { leading: true });
  38. render () {
  39. const { intl, hashtags, isLoading, hasMore, multiColumn } = this.props;
  40. const emptyMessage = <FormattedMessage id='empty_column.followed_tags' defaultMessage='You have not followed any hashtags yet. When you do, they will show up here.' />;
  41. return (
  42. <Column bindToDocument={!multiColumn}>
  43. <ColumnHeader
  44. icon='hashtag'
  45. title={intl.formatMessage(messages.heading)}
  46. showBackButton
  47. multiColumn={multiColumn}
  48. />
  49. <ScrollableList
  50. scrollKey='followed_tags'
  51. emptyMessage={emptyMessage}
  52. hasMore={hasMore}
  53. isLoading={isLoading}
  54. onLoadMore={this.handleLoadMore}
  55. bindToDocument={!multiColumn}
  56. >
  57. {hashtags.map((hashtag) => (
  58. <Hashtag
  59. key={hashtag.get('name')}
  60. name={hashtag.get('name')}
  61. to={`/tags/${hashtag.get('name')}`}
  62. withGraph={false}
  63. // Taken from ImmutableHashtag. Should maybe refactor ImmutableHashtag to accept more options?
  64. people={hashtag.getIn(['history', 0, 'accounts']) * 1 + hashtag.getIn(['history', 1, 'accounts']) * 1}
  65. history={hashtag.get('history').reverse().map((day) => day.get('uses')).toArray()}
  66. />
  67. ))}
  68. </ScrollableList>
  69. <Helmet>
  70. <meta name='robots' content='noindex' />
  71. </Helmet>
  72. </Column>
  73. );
  74. }
  75. }
  76. export default connect(mapStateToProps)(injectIntl(FollowedTags));