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.

117 lines
4.4 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePureComponent from 'react-immutable-pure-component';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { connect } from 'react-redux';
  6. import { FormattedMessage } from 'react-intl';
  7. import { fetchSuggestions } from 'mastodon/actions/suggestions';
  8. import { changeSetting, saveSettings } from 'mastodon/actions/settings';
  9. import { requestBrowserPermission } from 'mastodon/actions/notifications';
  10. import { markAsPartial } from 'mastodon/actions/timelines';
  11. import Column from 'mastodon/features/ui/components/column';
  12. import Account from './components/account';
  13. import imageGreeting from 'mastodon/../images/elephant_ui_greeting.svg';
  14. import Button from 'mastodon/components/button';
  15. import { Helmet } from 'react-helmet';
  16. const mapStateToProps = state => ({
  17. suggestions: state.getIn(['suggestions', 'items']),
  18. isLoading: state.getIn(['suggestions', 'isLoading']),
  19. });
  20. class FollowRecommendations extends ImmutablePureComponent {
  21. static contextTypes = {
  22. router: PropTypes.object.isRequired,
  23. };
  24. static propTypes = {
  25. dispatch: PropTypes.func.isRequired,
  26. suggestions: ImmutablePropTypes.list,
  27. isLoading: PropTypes.bool,
  28. };
  29. componentDidMount () {
  30. const { dispatch, suggestions } = this.props;
  31. // Don't re-fetch if we're e.g. navigating backwards to this page,
  32. // since we don't want followed accounts to disappear from the list
  33. if (suggestions.size === 0) {
  34. dispatch(fetchSuggestions(true));
  35. }
  36. }
  37. componentWillUnmount () {
  38. const { dispatch } = this.props;
  39. // Force the home timeline to be reloaded when the user navigates
  40. // to it; if the user is new, it would've been empty before
  41. dispatch(markAsPartial('home'));
  42. }
  43. handleDone = () => {
  44. const { dispatch } = this.props;
  45. const { router } = this.context;
  46. dispatch(requestBrowserPermission((permission) => {
  47. if (permission === 'granted') {
  48. dispatch(changeSetting(['notifications', 'alerts', 'follow'], true));
  49. dispatch(changeSetting(['notifications', 'alerts', 'favourite'], true));
  50. dispatch(changeSetting(['notifications', 'alerts', 'reblog'], true));
  51. dispatch(changeSetting(['notifications', 'alerts', 'mention'], true));
  52. dispatch(changeSetting(['notifications', 'alerts', 'poll'], true));
  53. dispatch(changeSetting(['notifications', 'alerts', 'status'], true));
  54. dispatch(saveSettings());
  55. }
  56. }));
  57. router.history.push('/home');
  58. };
  59. render () {
  60. const { suggestions, isLoading } = this.props;
  61. return (
  62. <Column>
  63. <div className='scrollable follow-recommendations-container'>
  64. <div className='column-title'>
  65. <svg viewBox='0 0 79 79' className='logo'>
  66. <use xlinkHref='#logo-symbol-icon' />
  67. </svg>
  68. <h3><FormattedMessage id='follow_recommendations.heading' defaultMessage="Follow people you'd like to see posts from! Here are some suggestions." /></h3>
  69. <p><FormattedMessage id='follow_recommendations.lead' defaultMessage="Posts from people you follow will show up in chronological order on your home feed. Don't be afraid to make mistakes, you can unfollow people just as easily any time!" /></p>
  70. </div>
  71. {!isLoading && (
  72. <React.Fragment>
  73. <div className='column-list'>
  74. {suggestions.size > 0 ? suggestions.map(suggestion => (
  75. <Account key={suggestion.get('account')} id={suggestion.get('account')} />
  76. )) : (
  77. <div className='column-list__empty-message'>
  78. <FormattedMessage id='empty_column.follow_recommendations' defaultMessage='Looks like no suggestions could be generated for you. You can try using search to look for people you might know or explore trending hashtags.' />
  79. </div>
  80. )}
  81. </div>
  82. <div className='column-actions'>
  83. <img src={imageGreeting} alt='' className='column-actions__background' />
  84. <Button onClick={this.handleDone}><FormattedMessage id='follow_recommendations.done' defaultMessage='Done' /></Button>
  85. </div>
  86. </React.Fragment>
  87. )}
  88. </div>
  89. <Helmet>
  90. <meta name='robots' content='noindex' />
  91. </Helmet>
  92. </Column>
  93. );
  94. }
  95. }
  96. export default connect(mapStateToProps)(FollowRecommendations);