2021-04-19 12:45:15 +00:00
import React from 'react' ;
import PropTypes from 'prop-types' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import { connect } from 'react-redux' ;
import { FormattedMessage } from 'react-intl' ;
import { fetchSuggestions } from 'mastodon/actions/suggestions' ;
import { changeSetting , saveSettings } from 'mastodon/actions/settings' ;
import { requestBrowserPermission } from 'mastodon/actions/notifications' ;
2021-05-07 12:33:57 +00:00
import { markAsPartial } from 'mastodon/actions/timelines' ;
2021-04-19 12:45:15 +00:00
import Column from 'mastodon/features/ui/components/column' ;
import Account from './components/account' ;
import Logo from 'mastodon/components/logo' ;
import imageGreeting from 'mastodon/../images/elephant_ui_greeting.svg' ;
import Button from 'mastodon/components/button' ;
const mapStateToProps = state => ( {
suggestions : state . getIn ( [ 'suggestions' , 'items' ] ) ,
isLoading : state . getIn ( [ 'suggestions' , 'isLoading' ] ) ,
} ) ;
export default @ connect ( mapStateToProps )
class FollowRecommendations extends ImmutablePureComponent {
static contextTypes = {
router : PropTypes . object . isRequired ,
} ;
static propTypes = {
dispatch : PropTypes . func . isRequired ,
suggestions : ImmutablePropTypes . list ,
isLoading : PropTypes . bool ,
} ;
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 ) ) ;
}
}
2021-05-07 12:33:57 +00:00
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' ) ) ;
}
2021-04-19 12:45:15 +00:00
handleDone = ( ) => {
const { dispatch } = this . props ;
const { router } = this . context ;
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 ( ) ) ;
}
} ) ) ;
2021-09-27 05:24:04 +00:00
router . history . push ( '/home' ) ;
2021-04-19 12:45:15 +00:00
}
render ( ) {
const { suggestions , isLoading } = this . props ;
return (
< Column >
2021-05-11 19:16:24 +00:00
< div className = 'scrollable follow-recommendations-container' >
2021-04-19 12:45:15 +00:00
< div className = 'column-title' >
< Logo / >
< h3 > < FormattedMessage id = 'follow_recommendations.heading' defaultMessage = "Follow people you'd like to see posts from! Here are some suggestions." / > < / h 3 >
< 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 >
< / d i v >
{ ! isLoading && (
< React . Fragment >
2021-05-05 21:57:29 +00:00
< div className = 'column-list' >
{ suggestions . size > 0 ? suggestions . map ( suggestion => (
2021-04-19 12:45:15 +00:00
< Account key = { suggestion . get ( 'account' ) } id = { suggestion . get ( 'account' ) } / >
2021-05-05 21:57:29 +00:00
) ) : (
< div className = 'column-list__empty-message' >
< 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.' / >
< / d i v >
) }
2021-04-19 12:45:15 +00:00
< / d i v >
< div className = 'column-actions' >
< img src = { imageGreeting } alt = '' className = 'column-actions__background' / >
< Button onClick = { this . handleDone } > < FormattedMessage id = 'follow_recommendations.done' defaultMessage = 'Done' / > < / B u t t o n >
< / d i v >
< / R e a c t . F r a g m e n t >
) }
< / d i v >
< / C o l u m n >
) ;
}
}