links.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. export default @connect(mapStateToProps)
  15. class Links extends React.PureComponent {
  16. static propTypes = {
  17. links: ImmutablePropTypes.list,
  18. isLoading: PropTypes.bool,
  19. dispatch: PropTypes.func.isRequired,
  20. };
  21. componentDidMount () {
  22. const { dispatch } = this.props;
  23. dispatch(fetchTrendingLinks());
  24. }
  25. render () {
  26. const { isLoading, links } = this.props;
  27. const banner = (
  28. <DismissableBanner id='explore/links'>
  29. <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.' />
  30. </DismissableBanner>
  31. );
  32. if (!isLoading && links.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 />) : links.map(link => (
  46. <Story
  47. key={link.get('id')}
  48. url={link.get('url')}
  49. title={link.get('title')}
  50. publisher={link.get('provider_name')}
  51. sharedTimes={link.getIn(['history', 0, 'accounts']) * 1 + link.getIn(['history', 1, 'accounts']) * 1}
  52. thumbnail={link.get('image')}
  53. blurhash={link.get('blurhash')}
  54. />
  55. ))}
  56. </div>
  57. );
  58. }
  59. }