import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { Helmet } from 'react-helmet'; import { withRouter } from 'react-router-dom'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { connect } from 'react-redux'; import { requestBrowserPermission } from 'flavours/glitch/actions/notifications'; import { changeSetting, saveSettings } from 'flavours/glitch/actions/settings'; import { fetchSuggestions } from 'flavours/glitch/actions/suggestions'; import { markAsPartial } from 'flavours/glitch/actions/timelines'; import Button from 'flavours/glitch/components/button'; import Column from 'flavours/glitch/features/ui/components/column'; import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router'; import imageGreeting from 'mastodon/../images/elephant_ui_greeting.svg'; import Account from './components/account'; const mapStateToProps = state => ({ suggestions: state.getIn(['suggestions', 'items']), isLoading: state.getIn(['suggestions', 'isLoading']), }); class FollowRecommendations extends ImmutablePureComponent { static propTypes = { dispatch: PropTypes.func.isRequired, suggestions: ImmutablePropTypes.list, isLoading: PropTypes.bool, ...WithRouterPropTypes, }; componentDidMount () { const { dispatch, suggestions } = this.props; // Don't re-fetch if we're e.g. navigating backwards to this page, // since we don't want followed accounts to disappear from the list if (suggestions.size === 0) { dispatch(fetchSuggestions(true)); } } componentWillUnmount () { const { dispatch } = this.props; // Force the home timeline to be reloaded when the user navigates // to it; if the user is new, it would've been empty before dispatch(markAsPartial('home')); } handleDone = () => { const { history, dispatch } = this.props; dispatch(requestBrowserPermission((permission) => { if (permission === 'granted') { dispatch(changeSetting(['notifications', 'alerts', 'follow'], true)); dispatch(changeSetting(['notifications', 'alerts', 'favourite'], true)); dispatch(changeSetting(['notifications', 'alerts', 'reblog'], true)); dispatch(changeSetting(['notifications', 'alerts', 'mention'], true)); dispatch(changeSetting(['notifications', 'alerts', 'poll'], true)); dispatch(changeSetting(['notifications', 'alerts', 'status'], true)); dispatch(saveSettings()); } })); history.push('/home'); }; render () { const { suggestions, isLoading } = this.props; return (

{!isLoading && ( <>
{suggestions.size > 0 ? suggestions.map(suggestion => ( )) : (
)}
)}
); } } export default withRouter(connect(mapStateToProps)(FollowRecommendations));