2022-05-28 09:02:04 -07:00
import React , { useEffect } from 'react' ;
import { FormattedMessage } from 'react-intl' ;
2023-06-25 15:50:01 -07:00
import { fetchReblogs , expandReblogs } from 'soapbox/actions/interactions' ;
2022-05-28 09:02:04 -07:00
import { fetchStatus } from 'soapbox/actions/statuses' ;
2022-11-15 08:00:49 -08:00
import ScrollableList from 'soapbox/components/scrollable-list' ;
2022-05-28 09:02:04 -07:00
import { Modal , Spinner } from 'soapbox/components/ui' ;
2022-11-15 08:13:54 -08:00
import AccountContainer from 'soapbox/containers/account-container' ;
2022-05-28 09:02:04 -07:00
import { useAppDispatch , useAppSelector } from 'soapbox/hooks' ;
interface IReblogsModal {
2023-02-15 13:26:27 -08:00
onClose : ( string : string ) = > void
statusId : string
2022-05-28 09:02:04 -07:00
}
const ReblogsModal : React.FC < IReblogsModal > = ( { onClose , statusId } ) = > {
const dispatch = useAppDispatch ( ) ;
2022-06-21 15:29:17 -07:00
const accountIds = useAppSelector ( ( state ) = > state . user_lists . reblogged_by . get ( statusId ) ? . items ) ;
2023-06-25 15:50:01 -07:00
const next = useAppSelector ( ( state ) = > state . user_lists . reblogged_by . get ( statusId ) ? . next ) ;
2022-05-28 09:02:04 -07:00
const fetchData = ( ) = > {
dispatch ( fetchReblogs ( statusId ) ) ;
dispatch ( fetchStatus ( statusId ) ) ;
} ;
useEffect ( ( ) = > {
fetchData ( ) ;
} , [ ] ) ;
const onClickClose = ( ) = > {
onClose ( 'REBLOGS' ) ;
} ;
2023-06-25 15:50:01 -07:00
const handleLoadMore = ( ) = > {
if ( next ) {
dispatch ( expandReblogs ( statusId , next ! ) ) ;
}
} ;
2022-05-28 09:02:04 -07:00
let body ;
if ( ! accountIds ) {
body = < Spinner / > ;
} else {
const emptyMessage = < FormattedMessage id = 'status.reblogs.empty' defaultMessage = 'No one has reposted this post yet. When someone does, they will show up here.' / > ;
body = (
< ScrollableList
scrollKey = 'reblogs'
emptyMessage = { emptyMessage }
2023-01-07 03:24:18 -08:00
className = 'max-w-full'
2022-05-28 09:02:04 -07:00
itemClassName = 'pb-3'
2023-06-24 15:47:16 -07:00
style = { { height : '80vh' } }
useWindowScroll = { false }
2023-06-25 15:50:01 -07:00
onLoadMore = { handleLoadMore }
hasMore = { ! ! next }
2022-05-28 09:02:04 -07:00
>
2022-06-21 15:29:17 -07:00
{ accountIds . map ( ( id ) = >
2022-05-28 09:02:04 -07:00
< AccountContainer key = { id } id = { id } / > ,
) }
< / ScrollableList >
) ;
}
return (
< Modal
title = { < FormattedMessage id = 'column.reblogs' defaultMessage = 'Reposts' / > }
onClose = { onClickClose }
>
{ body }
< / Modal >
) ;
} ;
export default ReblogsModal ;