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.

63 lines
1.9 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { ImmutableHashtag as Hashtag } from 'mastodon/components/hashtag';
  5. import LoadingIndicator from 'mastodon/components/loading_indicator';
  6. import { connect } from 'react-redux';
  7. import { fetchTrendingHashtags } from 'mastodon/actions/trends';
  8. import { FormattedMessage } from 'react-intl';
  9. import DismissableBanner from 'mastodon/components/dismissable_banner';
  10. const mapStateToProps = state => ({
  11. hashtags: state.getIn(['trends', 'tags', 'items']),
  12. isLoadingHashtags: state.getIn(['trends', 'tags', 'isLoading']),
  13. });
  14. class Tags extends React.PureComponent {
  15. static propTypes = {
  16. hashtags: ImmutablePropTypes.list,
  17. isLoading: PropTypes.bool,
  18. dispatch: PropTypes.func.isRequired,
  19. };
  20. componentDidMount () {
  21. const { dispatch } = this.props;
  22. dispatch(fetchTrendingHashtags());
  23. }
  24. render () {
  25. const { isLoading, hashtags } = this.props;
  26. const banner = (
  27. <DismissableBanner id='explore/tags'>
  28. <FormattedMessage id='dismissable_banner.explore_tags' defaultMessage='These hashtags are gaining traction among people on this and other servers of the decentralized network right now.' />
  29. </DismissableBanner>
  30. );
  31. if (!isLoading && hashtags.isEmpty()) {
  32. return (
  33. <div className='explore__links scrollable scrollable--flex'>
  34. {banner}
  35. <div className='empty-column-indicator'>
  36. <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />
  37. </div>
  38. </div>
  39. );
  40. }
  41. return (
  42. <div className='explore__links'>
  43. {banner}
  44. {isLoading ? (<LoadingIndicator />) : hashtags.map(hashtag => (
  45. <Hashtag key={hashtag.get('name')} hashtag={hashtag} />
  46. ))}
  47. </div>
  48. );
  49. }
  50. }
  51. export default connect(mapStateToProps)(Tags);