2017-05-02 20:04:16 -04:00
import React from 'react' ;
2016-12-26 15:33:51 -05:00
import { connect } from 'react-redux' ;
2017-04-21 14:05:35 -04:00
import PropTypes from 'prop-types' ;
2016-12-26 15:33:51 -05:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2018-08-26 10:39:37 -04:00
import { debounce } from 'lodash' ;
2017-12-04 02:26:40 -05:00
import LoadingIndicator from 'flavours/glitch/components/loading_indicator' ;
import Column from 'flavours/glitch/features/ui/components/column' ;
import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim' ;
2016-12-26 15:33:51 -05:00
import AccountAuthorizeContainer from './containers/account_authorize_container' ;
2017-12-04 02:26:40 -05:00
import { fetchFollowRequests , expandFollowRequests } from 'flavours/glitch/actions/accounts' ;
2018-08-26 10:39:37 -04:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2017-05-02 20:04:16 -04:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2018-08-26 10:39:37 -04:00
import ScrollableList from 'flavours/glitch/components/scrollable_list' ;
2016-12-26 15:33:51 -05:00
const messages = defineMessages ( {
2017-05-20 11:31:47 -04:00
heading : { id : 'column.follow_requests' , defaultMessage : 'Follow requests' } ,
2016-12-26 15:33:51 -05:00
} ) ;
const mapStateToProps = state => ( {
2017-05-20 11:31:47 -04:00
accountIds : state . getIn ( [ 'user_lists' , 'follow_requests' , 'items' ] ) ,
2019-02-16 05:56:09 -05:00
hasMore : ! ! state . getIn ( [ 'user_lists' , 'follow_requests' , 'next' ] ) ,
2016-12-26 15:33:51 -05:00
} ) ;
2017-06-23 13:36:54 -04:00
@ connect ( mapStateToProps )
@ injectIntl
export default class FollowRequests extends ImmutablePureComponent {
2016-12-26 15:33:51 -05:00
2017-05-12 08:44:10 -04:00
static propTypes = {
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
2019-02-16 05:56:09 -05:00
hasMore : PropTypes . bool ,
2017-05-12 08:44:10 -04:00
accountIds : ImmutablePropTypes . list ,
2017-05-20 11:31:47 -04:00
intl : PropTypes . object . isRequired ,
2017-05-12 08:44:10 -04:00
} ;
2016-12-26 15:33:51 -05:00
componentWillMount ( ) {
this . props . dispatch ( fetchFollowRequests ( ) ) ;
2017-04-21 14:05:35 -04:00
}
2016-12-26 15:33:51 -05:00
2018-08-26 10:39:37 -04:00
handleLoadMore = debounce ( ( ) => {
this . props . dispatch ( expandFollowRequests ( ) ) ;
} , 300 , { leading : true } ) ;
2016-12-26 15:33:51 -05:00
2018-09-03 07:32:35 -04:00
shouldUpdateScroll = ( prevRouterProps , { location } ) => {
2018-10-06 12:53:49 -04:00
if ( ( ( ( prevRouterProps || { } ) . location || { } ) . state || { } ) . mastodonModalOpen ) return false ;
2018-09-03 07:32:35 -04:00
return ! ( location . state && location . state . mastodonModalOpen ) ;
}
2016-12-26 15:33:51 -05:00
render ( ) {
2019-02-16 05:56:09 -05:00
const { intl , accountIds , hasMore } = this . props ;
2016-12-26 15:33:51 -05:00
if ( ! accountIds ) {
return (
2017-08-06 15:27:47 -04:00
< Column name = 'follow-requests' >
2016-12-26 15:33:51 -05:00
< LoadingIndicator / >
< / C o l u m n >
) ;
}
2018-08-26 10:39:37 -04:00
const emptyMessage = < FormattedMessage id = 'empty_column.follow_requests' defaultMessage = "You don't have any follow requests yet. When you receive one, it will show up here." / > ;
2016-12-26 15:33:51 -05:00
return (
2019-05-25 20:55:37 -04:00
< Column name = 'follow-requests' icon = 'user-plus' heading = { intl . formatMessage ( messages . heading ) } >
2017-01-30 09:22:04 -05:00
< ColumnBackButtonSlim / >
2017-06-20 14:40:03 -04:00
2018-08-26 10:39:37 -04:00
< ScrollableList
scrollKey = 'follow_requests'
onLoadMore = { this . handleLoadMore }
2019-02-16 05:56:09 -05:00
hasMore = { hasMore }
2018-08-26 10:39:37 -04:00
shouldUpdateScroll = { this . shouldUpdateScroll }
emptyMessage = { emptyMessage }
>
{ accountIds . map ( id =>
< AccountAuthorizeContainer key = { id } id = { id } / >
) }
< / S c r o l l a b l e L i s t >
2016-12-26 15:33:51 -05:00
< / C o l u m n >
) ;
}
2017-04-21 14:05:35 -04:00
2017-05-12 08:44:10 -04:00
}