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.

71 lines
2.2 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import Story from './components/story';
  5. import LoadingIndicator from 'mastodon/components/loading_indicator';
  6. import { connect } from 'react-redux';
  7. import { fetchTrendingLinks } from 'mastodon/actions/trends';
  8. import { FormattedMessage } from 'react-intl';
  9. import DismissableBanner from 'mastodon/components/dismissable_banner';
  10. const mapStateToProps = state => ({
  11. links: state.getIn(['trends', 'links', 'items']),
  12. isLoading: state.getIn(['trends', 'links', 'isLoading']),
  13. });
  14. class Links extends React.PureComponent {
  15. static propTypes = {
  16. links: ImmutablePropTypes.list,
  17. isLoading: PropTypes.bool,
  18. dispatch: PropTypes.func.isRequired,
  19. };
  20. componentDidMount () {
  21. const { dispatch } = this.props;
  22. dispatch(fetchTrendingLinks());
  23. }
  24. render () {
  25. const { isLoading, links } = this.props;
  26. const banner = (
  27. <DismissableBanner id='explore/links'>
  28. <FormattedMessage id='dismissable_banner.explore_links' defaultMessage='These news stories are being talked about by people on this and other servers of the decentralized network right now.' />
  29. </DismissableBanner>
  30. );
  31. if (!isLoading && links.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 />) : links.map(link => (
  45. <Story
  46. key={link.get('id')}
  47. url={link.get('url')}
  48. title={link.get('title')}
  49. publisher={link.get('provider_name')}
  50. sharedTimes={link.getIn(['history', 0, 'accounts']) * 1 + link.getIn(['history', 1, 'accounts']) * 1}
  51. thumbnail={link.get('image')}
  52. blurhash={link.get('blurhash')}
  53. />
  54. ))}
  55. </div>
  56. );
  57. }
  58. }
  59. export default connect(mapStateToProps)(Links);