2017-04-22 03:05:35 +09:00
import PropTypes from 'prop-types' ;
2023-05-28 23:38:10 +09:00
import { FormattedMessage } from 'react-intl' ;
2016-11-14 04:42:54 +09:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2023-05-28 23:38:10 +09:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import { connect } from 'react-redux' ;
2018-08-26 23:39:37 +09:00
import { debounce } from 'lodash' ;
2023-05-28 23:38:10 +09:00
import { TimelineHint } from 'flavours/glitch/components/timeline_hint' ;
2023-04-12 19:44:58 +09:00
import BundleColumnError from 'flavours/glitch/features/ui/components/bundle_column_error' ;
2023-05-28 23:38:10 +09:00
import { normalizeForLookup } from 'flavours/glitch/reducers/accounts_map' ;
import { getAccountHidden } from 'flavours/glitch/selectors' ;
2023-11-15 20:01:51 +09:00
import {
lookupAccount ,
fetchAccount ,
fetchFollowers ,
expandFollowers ,
} from '../../actions/accounts' ;
import { LoadingIndicator } from '../../components/loading_indicator' ;
import ScrollableList from '../../components/scrollable_list' ;
import AccountContainer from '../../containers/account_container' ;
import ProfileColumnHeader from '../account/components/profile_column_header' ;
2023-11-04 00:00:03 +09:00
import { LimitedAccountHint } from '../account_timeline/components/limited_account_hint' ;
2023-11-15 20:01:51 +09:00
import HeaderContainer from '../account_timeline/containers/header_container' ;
import Column from '../ui/components/column' ;
2023-05-28 23:38:10 +09:00
2021-09-27 14:23:48 +09:00
const mapStateToProps = ( state , { params : { acct , id } } ) => {
2022-10-24 06:38:08 +09:00
const accountId = id || state . getIn ( [ 'accounts_map' , normalizeForLookup ( acct ) ] ) ;
2021-09-26 12:46:13 +09:00
if ( ! accountId ) {
return {
isLoading : true ,
} ;
}
return {
accountId ,
remote : ! ! ( state . getIn ( [ 'accounts' , accountId , 'acct' ] ) !== state . getIn ( [ 'accounts' , accountId , 'username' ] ) ) ,
remoteUrl : state . getIn ( [ 'accounts' , accountId , 'url' ] ) ,
isAccount : ! ! state . getIn ( [ 'accounts' , accountId ] ) ,
accountIds : state . getIn ( [ 'user_lists' , 'followers' , accountId , 'items' ] ) ,
hasMore : ! ! state . getIn ( [ 'user_lists' , 'followers' , accountId , 'next' ] ) ,
isLoading : state . getIn ( [ 'user_lists' , 'followers' , accountId , 'isLoading' ] , true ) ,
2022-05-10 16:44:35 +09:00
suspended : state . getIn ( [ 'accounts' , accountId , 'suspended' ] , false ) ,
2023-11-09 21:58:02 +09:00
hideCollections : state . getIn ( [ 'accounts' , accountId , 'hide_collections' ] , false ) ,
2022-05-10 16:44:35 +09:00
hidden : getAccountHidden ( state , accountId ) ,
2021-09-26 12:46:13 +09:00
} ;
} ;
2016-10-28 04:59:56 +09:00
2020-06-15 05:29:40 +09:00
const RemoteHint = ( { url } ) => (
< TimelineHint url = { url } resource = { < FormattedMessage id = 'timeline_hint.resources.followers' defaultMessage = 'Followers' / > } / >
) ;
RemoteHint . propTypes = {
url : PropTypes . string . isRequired ,
} ;
2019-09-09 22:16:08 +09:00
class Followers extends ImmutablePureComponent {
2016-10-28 04:59:56 +09:00
2017-05-12 21:44:10 +09:00
static propTypes = {
2021-09-26 12:46:13 +09:00
params : PropTypes . shape ( {
2021-09-27 14:23:48 +09:00
acct : PropTypes . string ,
id : PropTypes . string ,
2021-09-26 12:46:13 +09:00
} ) . isRequired ,
accountId : PropTypes . string ,
2017-05-12 21:44:10 +09:00
dispatch : PropTypes . func . isRequired ,
2017-05-21 00:31:47 +09:00
accountIds : ImmutablePropTypes . list ,
2017-06-06 01:18:56 +09:00
hasMore : PropTypes . bool ,
2020-04-12 20:38:00 +09:00
isLoading : PropTypes . bool ,
2019-04-09 12:02:48 +09:00
isAccount : PropTypes . bool ,
2022-05-10 16:44:35 +09:00
suspended : PropTypes . bool ,
hidden : PropTypes . bool ,
2020-06-15 05:29:40 +09:00
remote : PropTypes . bool ,
remoteUrl : PropTypes . string ,
2019-07-19 16:25:22 +09:00
multiColumn : PropTypes . bool ,
2017-05-12 21:44:10 +09:00
} ;
2016-10-28 04:59:56 +09:00
2021-09-26 12:46:13 +09:00
_load ( ) {
2021-09-27 14:23:48 +09:00
const { accountId , isAccount , dispatch } = this . props ;
2021-09-26 12:46:13 +09:00
2021-09-27 14:23:48 +09:00
if ( ! isAccount ) dispatch ( fetchAccount ( accountId ) ) ;
2021-09-26 12:46:13 +09:00
dispatch ( fetchFollowers ( accountId ) ) ;
2017-04-22 03:05:35 +09:00
}
2016-10-28 04:59:56 +09:00
2021-09-26 12:46:13 +09:00
componentDidMount ( ) {
const { params : { acct } , accountId , dispatch } = this . props ;
if ( accountId ) {
this . _load ( ) ;
} else {
dispatch ( lookupAccount ( acct ) ) ;
2016-10-28 04:59:56 +09:00
}
2017-04-22 03:05:35 +09:00
}
2016-10-28 04:59:56 +09:00
2021-09-26 12:46:13 +09:00
componentDidUpdate ( prevProps ) {
const { params : { acct } , accountId , dispatch } = this . props ;
if ( prevProps . accountId !== accountId && accountId ) {
this . _load ( ) ;
} else if ( prevProps . params . acct !== acct ) {
dispatch ( lookupAccount ( acct ) ) ;
}
2019-03-09 04:34:31 +09:00
}
2018-08-26 23:39:37 +09:00
handleLoadMore = debounce ( ( ) => {
2021-09-26 12:46:13 +09:00
this . props . dispatch ( expandFollowers ( this . props . accountId ) ) ;
2018-08-26 23:39:37 +09:00
} , 300 , { leading : true } ) ;
2017-01-31 05:40:55 +09:00
2019-03-09 04:34:31 +09:00
setRef = c => {
this . column = c ;
2023-02-04 04:52:07 +09:00
} ;
2019-03-09 04:34:31 +09:00
2021-09-26 12:46:13 +09:00
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
2023-02-04 04:52:07 +09:00
} ;
2021-09-26 12:46:13 +09:00
2016-10-28 04:59:56 +09:00
render ( ) {
2023-11-09 21:58:02 +09:00
const { accountId , accountIds , hasMore , isAccount , multiColumn , isLoading , suspended , hidden , remote , remoteUrl , hideCollections } = this . props ;
2019-04-09 12:02:48 +09:00
if ( ! isAccount ) {
return (
2023-04-12 19:44:58 +09:00
< BundleColumnError multiColumn = { multiColumn } errorType = 'routing' / >
2019-04-09 12:02:48 +09:00
) ;
}
2017-06-05 21:13:20 +09:00
2016-10-28 04:59:56 +09:00
if ( ! accountIds ) {
2017-01-31 05:40:55 +09:00
return (
< Column >
< LoadingIndicator / >
< / Column >
) ;
2016-10-28 04:59:56 +09:00
}
2020-06-15 05:29:40 +09:00
let emptyMessage ;
2022-05-10 16:44:35 +09:00
const forceEmptyState = suspended || hidden ;
if ( suspended ) {
emptyMessage = < FormattedMessage id = 'empty_column.account_suspended' defaultMessage = 'Account suspended' / > ;
} else if ( hidden ) {
emptyMessage = < LimitedAccountHint accountId = { accountId } / > ;
2023-11-09 21:58:02 +09:00
} else if ( hideCollections && accountIds . isEmpty ( ) ) {
emptyMessage = < FormattedMessage id = 'empty_column.account_hides_collections' defaultMessage = 'This user has chosen to not make this information available' / > ;
2022-05-10 16:44:35 +09:00
} else if ( remote && accountIds . isEmpty ( ) ) {
2020-06-15 05:29:40 +09:00
emptyMessage = < RemoteHint url = { remoteUrl } / > ;
} else {
emptyMessage = < FormattedMessage id = 'account.followers.empty' defaultMessage = 'No one follows this user yet.' / > ;
}
const remoteMessage = remote ? < RemoteHint url = { remoteUrl } / > : null ;
2017-06-05 21:13:20 +09:00
2016-10-28 04:59:56 +09:00
return (
2019-03-09 04:34:31 +09:00
< Column ref = { this . setRef } >
2019-08-02 02:17:17 +09:00
< ProfileColumnHeader onClick = { this . handleHeaderClick } multiColumn = { multiColumn } / >
2017-02-01 06:34:33 +09:00
2018-08-26 23:39:37 +09:00
< ScrollableList
scrollKey = 'followers'
2022-05-10 16:44:35 +09:00
hasMore = { ! forceEmptyState && hasMore }
2020-04-12 20:38:00 +09:00
isLoading = { isLoading }
2018-08-26 23:39:37 +09:00
onLoadMore = { this . handleLoadMore }
2021-09-26 12:46:13 +09:00
prepend = { < HeaderContainer accountId = { this . props . accountId } hideTabs / > }
2018-08-29 08:19:58 +09:00
alwaysPrepend
2020-06-15 05:29:40 +09:00
append = { remoteMessage }
2018-08-26 23:39:37 +09:00
emptyMessage = { emptyMessage }
2019-07-19 16:25:22 +09:00
bindToDocument = { ! multiColumn }
2018-08-26 23:39:37 +09:00
>
{ accountIds . map ( id =>
2020-03-09 00:02:36 +09:00
< AccountContainer key = { id } id = { id } withNote = { false } / > ,
2018-08-26 23:39:37 +09:00
) }
< / ScrollableList >
2017-01-31 05:40:55 +09:00
< / Column >
2016-10-28 04:59:56 +09:00
) ;
}
2017-04-22 03:05:35 +09:00
}
2023-03-25 07:15:25 +09:00
export default connect ( mapStateToProps ) ( Followers ) ;