tags.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. export default @connect(mapStateToProps)
  15. class Tags extends React.PureComponent {
  16. static propTypes = {
  17. hashtags: ImmutablePropTypes.list,
  18. isLoading: PropTypes.bool,
  19. dispatch: PropTypes.func.isRequired,
  20. };
  21. componentDidMount () {
  22. const { dispatch } = this.props;
  23. dispatch(fetchTrendingHashtags());
  24. }
  25. render () {
  26. const { isLoading, hashtags } = this.props;
  27. const banner = (
  28. <DismissableBanner id='explore/tags'>
  29. <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.' />
  30. </DismissableBanner>
  31. );
  32. if (!isLoading && hashtags.isEmpty()) {
  33. return (
  34. <div className='explore__links scrollable scrollable--flex'>
  35. {banner}
  36. <div className='empty-column-indicator'>
  37. <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />
  38. </div>
  39. </div>
  40. );
  41. }
  42. return (
  43. <div className='explore__links'>
  44. {banner}
  45. {isLoading ? (<LoadingIndicator />) : hashtags.map(hashtag => (
  46. <Hashtag key={hashtag.get('name')} hashtag={hashtag} />
  47. ))}
  48. </div>
  49. );
  50. }
  51. }