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.

109 lines
4.2 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 Logo from 'mastodon/components/logo';
  14. import imageGreeting from 'mastodon/../images/elephant_ui_greeting.svg';
  15. import Button from 'mastodon/components/button';
  16. const mapStateToProps = state => ({
  17. suggestions: state.getIn(['suggestions', 'items']),
  18. isLoading: state.getIn(['suggestions', 'isLoading']),
  19. });
  20. export default @connect(mapStateToProps)
  21. class FollowRecommendations extends ImmutablePureComponent {
  22. static contextTypes = {
  23. router: PropTypes.object.isRequired,
  24. };
  25. static propTypes = {
  26. dispatch: PropTypes.func.isRequired,
  27. suggestions: ImmutablePropTypes.list,
  28. isLoading: PropTypes.bool,
  29. };
  30. componentDidMount () {
  31. const { dispatch, suggestions } = this.props;
  32. // Don't re-fetch if we're e.g. navigating backwards to this page,
  33. // since we don't want followed accounts to disappear from the list
  34. if (suggestions.size === 0) {
  35. dispatch(fetchSuggestions(true));
  36. }
  37. }
  38. componentWillUnmount () {
  39. const { dispatch } = this.props;
  40. // Force the home timeline to be reloaded when the user navigates
  41. // to it; if the user is new, it would've been empty before
  42. dispatch(markAsPartial('home'));
  43. }
  44. handleDone = () => {
  45. const { dispatch } = this.props;
  46. const { router } = this.context;
  47. dispatch(requestBrowserPermission((permission) => {
  48. if (permission === 'granted') {
  49. dispatch(changeSetting(['notifications', 'alerts', 'follow'], true));
  50. dispatch(changeSetting(['notifications', 'alerts', 'favourite'], true));
  51. dispatch(changeSetting(['notifications', 'alerts', 'reblog'], true));
  52. dispatch(changeSetting(['notifications', 'alerts', 'mention'], true));
  53. dispatch(changeSetting(['notifications', 'alerts', 'poll'], true));
  54. dispatch(changeSetting(['notifications', 'alerts', 'status'], true));
  55. dispatch(saveSettings());
  56. }
  57. }));
  58. router.history.push('/timelines/home');
  59. }
  60. render () {
  61. const { suggestions, isLoading } = this.props;
  62. return (
  63. <Column>
  64. <div className='scrollable follow-recommendations-container'>
  65. <div className='column-title'>
  66. <Logo />
  67. <h3><FormattedMessage id='follow_recommendations.heading' defaultMessage="Follow people you'd like to see posts from! Here are some suggestions." /></h3>
  68. <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>
  69. </div>
  70. {!isLoading && (
  71. <React.Fragment>
  72. <div className='column-list'>
  73. {suggestions.size > 0 ? suggestions.map(suggestion => (
  74. <Account key={suggestion.get('account')} id={suggestion.get('account')} />
  75. )) : (
  76. <div className='column-list__empty-message'>
  77. <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.' />
  78. </div>
  79. )}
  80. </div>
  81. <div className='column-actions'>
  82. <img src={imageGreeting} alt='' className='column-actions__background' />
  83. <Button onClick={this.handleDone}><FormattedMessage id='follow_recommendations.done' defaultMessage='Done' /></Button>
  84. </div>
  85. </React.Fragment>
  86. )}
  87. </div>
  88. </Column>
  89. );
  90. }
  91. }