2021-04-19 21:45:15 +09:00
import PropTypes from 'prop-types' ;
2023-05-28 23:38:10 +09:00
import { FormattedMessage } from 'react-intl' ;
import { Helmet } from 'react-helmet' ;
2023-10-20 02:44:55 +09:00
import { withRouter } from 'react-router-dom' ;
2023-05-28 23:38:10 +09:00
2021-04-19 21:45:15 +09:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2023-05-28 23:38:10 +09:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2021-04-19 21:45:15 +09:00
import { connect } from 'react-redux' ;
2023-05-28 23:38:10 +09:00
2021-04-19 21:45:15 +09:00
import { requestBrowserPermission } from 'flavours/glitch/actions/notifications' ;
2023-05-28 23:38:10 +09:00
import { changeSetting , saveSettings } from 'flavours/glitch/actions/settings' ;
import { fetchSuggestions } from 'flavours/glitch/actions/suggestions' ;
2021-05-07 21:33:57 +09:00
import { markAsPartial } from 'flavours/glitch/actions/timelines' ;
2023-10-23 16:43:00 +09:00
import { Button } from 'flavours/glitch/components/button' ;
2021-04-19 21:45:15 +09:00
import Column from 'flavours/glitch/features/ui/components/column' ;
2023-10-20 02:44:55 +09:00
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router' ;
2021-04-19 21:45:15 +09:00
import imageGreeting from 'mastodon/../images/elephant_ui_greeting.svg' ;
2023-05-28 23:38:10 +09:00
import Account from './components/account' ;
2021-04-19 21:45:15 +09:00
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 ,
2023-10-20 02:44:55 +09:00
... WithRouterPropTypes ,
2021-04-19 21:45:15 +09:00
} ;
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 21:33:57 +09: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 21:45:15 +09:00
handleDone = ( ) => {
2023-10-20 02:44:55 +09:00
const { history , dispatch } = this . props ;
2021-04-19 21:45:15 +09:00
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 ( ) ) ;
}
} ) ) ;
2023-10-20 02:44:55 +09:00
history . push ( '/home' ) ;
2023-02-04 04:52:07 +09:00
} ;
2021-04-19 21:45:15 +09:00
render ( ) {
const { suggestions , isLoading } = this . props ;
return (
< Column >
2021-05-12 04:16:24 +09:00
< div className = 'scrollable follow-recommendations-container' >
2021-04-19 21:45:15 +09:00
< div className = 'column-title' >
2022-09-29 15:55:14 +09:00
< svg viewBox = '0 0 79 79' className = 'logo' >
< use xlinkHref = '#logo-symbol-icon' / >
< / svg >
2021-04-19 21:45:15 +09:00
< h3 > < FormattedMessage id = 'follow_recommendations.heading' defaultMessage = "Follow people you'd like to see posts from! Here are some suggestions." / > < / h3 >
< 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 >
< / div >
{ ! isLoading && (
2023-05-28 21:56:24 +09:00
< >
2021-05-06 06:57:29 +09:00
< div className = 'column-list' >
{ suggestions . size > 0 ? suggestions . map ( suggestion => (
2021-04-19 21:45:15 +09:00
< Account key = { suggestion . get ( 'account' ) } id = { suggestion . get ( 'account' ) } / >
2021-05-06 06:57:29 +09: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.' / >
< / div >
) }
2021-04-19 21:45:15 +09:00
< / div >
< div className = 'column-actions' >
< img src = { imageGreeting } alt = '' className = 'column-actions__background' / >
< Button onClick = { this . handleDone } > < FormattedMessage id = 'follow_recommendations.done' defaultMessage = 'Done' / > < / Button >
< / div >
2023-05-28 21:56:24 +09:00
< / >
2021-04-19 21:45:15 +09:00
) }
< / div >
2022-10-20 21:35:29 +09:00
< Helmet >
< meta name = 'robots' content = 'noindex' / >
< / Helmet >
2021-04-19 21:45:15 +09:00
< / Column >
) ;
}
}
2023-03-25 07:15:25 +09:00
2023-10-20 02:44:55 +09:00
export default withRouter ( connect ( mapStateToProps ) ( FollowRecommendations ) ) ;