2022-06-16 12:32:17 -07:00
import debounce from 'lodash/debounce' ;
2022-04-11 14:02:37 -07:00
import React from 'react' ;
import { defineMessages , useIntl , FormattedMessage } from 'react-intl' ;
import { useDispatch } from 'react-redux' ;
import { fetchFollowRequests , expandFollowRequests } from 'soapbox/actions/accounts' ;
2022-11-15 08:00:49 -08:00
import ScrollableList from 'soapbox/components/scrollable-list' ;
2022-11-30 09:19:16 -08:00
import { Column , Spinner } from ' soapbox / components / ui ' ;
2022-04-11 14:02:37 -07:00
import { useAppSelector } from 'soapbox/hooks' ;
2022-11-15 11:00:40 -08:00
import AccountAuthorize from './components/account-authorize' ;
2022-04-11 14:02:37 -07:00
const messages = defineMessages ( {
heading : { id : 'column.follow_requests' , defaultMessage : 'Follow requests' } ,
} ) ;
const handleLoadMore = debounce ( ( dispatch ) = > {
dispatch ( expandFollowRequests ( ) ) ;
} , 300 , { leading : true } ) ;
const FollowRequests : React.FC = ( ) = > {
const dispatch = useDispatch ( ) ;
const intl = useIntl ( ) ;
2022-06-21 15:29:17 -07:00
const accountIds = useAppSelector ( ( state ) = > state . user_lists . follow_requests . items ) ;
const hasMore = useAppSelector ( ( state ) = > ! ! state . user_lists . follow_requests . next ) ;
2022-04-11 14:02:37 -07:00
React . useEffect ( ( ) = > {
dispatch ( fetchFollowRequests ( ) ) ;
} , [ ] ) ;
if ( ! accountIds ) {
return (
< Column >
< Spinner / >
< / Column >
) ;
}
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." / > ;
return (
2022-11-30 09:19:16 -08:00
< Column label = { intl . formatMessage ( messages . heading ) } >
2022-04-11 14:02:37 -07:00
< ScrollableList
scrollKey = 'follow_requests'
onLoadMore = { ( ) = > handleLoadMore ( dispatch ) }
hasMore = { hasMore }
emptyMessage = { emptyMessage }
>
{ accountIds . map ( id = >
< AccountAuthorize key = { id } id = { id } / > ,
) }
< / ScrollableList >
< / Column >
) ;
} ;
export default FollowRequests ;