2020-08-17 21:07:16 +01:00
import React from 'react'
2020-08-17 21:59:29 +01:00
import PropTypes from 'prop-types'
2020-08-17 21:39:25 +01:00
import { connect } from 'react-redux'
2020-06-07 18:27:08 +01:00
import { FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
import debounce from 'lodash.debounce'
import { me } from '../initial_state'
import { fetchFollowRequests , expandFollowRequests } from '../actions/accounts'
import AccountAuthorize from '../components/account_authorize'
import Block from '../components/block'
import ScrollableList from '../components/scrollable_list'
import Text from '../components/text'
class FollowRequests extends ImmutablePureComponent {
componentWillMount ( ) {
this . props . onFetchFollowRequests ( )
}
handleLoadMore = debounce ( ( ) => {
this . props . onExpandFollowRequests ( )
} , 300 , { leading : true } )
render ( ) {
const {
accountIds ,
hasMore ,
isLoading ,
locked ,
} = this . props
const unlockedPrependMessage = locked ? null : (
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . px15 , _s . py15 , _s . borderBottom1PX , _s . borderColorSecondary ] . join ( ' ' ) } >
2020-06-07 18:27:08 +01:00
< Text >
< FormattedMessage
id = 'follow_requests.unlocked_explanation'
defaultMessage = 'Even though your account is not locked, the {domain} staff thought you might want to review follow requests from these accounts manually.'
values = { { domain : 'Gab.com' } }
/ >
< / T e x t >
< / d i v >
)
return (
< Block >
{ unlockedPrependMessage }
< ScrollableList
scrollKey = 'follow_requests'
onLoadMore = { this . handleLoadMore }
hasMore = { hasMore }
isLoading = { isLoading }
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." / > }
>
{
2020-06-10 21:05:15 +01:00
accountIds && accountIds . map ( ( id ) =>
2020-06-07 18:27:08 +01:00
< AccountAuthorize key = { id } id = { id } / >
)
}
< / S c r o l l a b l e L i s t >
< / B l o c k >
)
}
}
2020-08-19 01:22:15 +01:00
const mapStateToProps = ( state ) => ( {
accountIds : state . getIn ( [ 'user_lists' , 'follow_requests' , me , 'items' ] ) ,
isLoading : state . getIn ( [ 'user_lists' , 'follow_requests' , me , 'isLoading' ] ) ,
hasMore : ! ! state . getIn ( [ 'user_lists' , 'follow_requests' , me , 'next' ] ) ,
locked : ! ! state . getIn ( [ 'accounts' , me , 'locked' ] ) ,
} )
const mapDispatchToProps = ( dispatch ) => ( {
onFetchFollowRequests ( ) {
dispatch ( fetchFollowRequests ( ) )
} ,
onExpandFollowRequests ( ) {
dispatch ( expandFollowRequests ( ) )
} ,
} )
FollowRequests . propTypes = {
accountIds : ImmutablePropTypes . list ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
locked : PropTypes . bool ,
onFetchFollowRequests : PropTypes . func . isRequired ,
onExpandFollowRequests : PropTypes . func . isRequired ,
}
export default connect ( mapStateToProps , mapDispatchToProps ) ( FollowRequests )