trends.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react';
  2. import ImmutablePureComponent from 'react-immutable-pure-component';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import Hashtag from 'mastodon/components/hashtag';
  6. import { FormattedMessage } from 'react-intl';
  7. export default class Trends extends ImmutablePureComponent {
  8. static defaultProps = {
  9. loading: false,
  10. };
  11. static propTypes = {
  12. trends: ImmutablePropTypes.list,
  13. fetchTrends: PropTypes.func.isRequired,
  14. };
  15. componentDidMount () {
  16. this.props.fetchTrends();
  17. this.refreshInterval = setInterval(() => this.props.fetchTrends(), 900 * 1000);
  18. }
  19. componentWillUnmount () {
  20. if (this.refreshInterval) {
  21. clearInterval(this.refreshInterval);
  22. }
  23. }
  24. render () {
  25. const { trends } = this.props;
  26. if (!trends || trends.isEmpty()) {
  27. return null;
  28. }
  29. return (
  30. <div className='getting-started__trends'>
  31. <h4><FormattedMessage id='trends.trending_now' defaultMessage='Trending now' /></h4>
  32. {trends.take(3).map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
  33. </div>
  34. );
  35. }
  36. }