@ -2,20 +2,21 @@ import React from 'react';
import { connect } from 'react-redux' ;
import { connect } from 'react-redux' ;
import PropTypes from 'prop-types' ;
import PropTypes from 'prop-types' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import { debounce } from 'lodash' ;
import LoadingIndicator from 'flavours/glitch/components/loading_indicator' ;
import LoadingIndicator from 'flavours/glitch/components/loading_indicator' ;
import {
import {
fetchAccount ,
fetchAccount ,
fetchFollowers ,
fetchFollowers ,
expandFollowers ,
expandFollowers ,
} from 'flavours/glitch/actions/accounts' ;
} from 'flavours/glitch/actions/accounts' ;
import { ScrollContainer } from 'react-router-scroll-4 ';
import { FormattedMessage } from 'react-intl ';
import AccountContainer from 'flavours/glitch/containers/account_container' ;
import AccountContainer from 'flavours/glitch/containers/account_container' ;
import Column from 'flavours/glitch/features/ui/components/column' ;
import Column from 'flavours/glitch/features/ui/components/column' ;
import ProfileColumnHeader from 'flavours/glitch/features/account/components/profile_column_header' ;
import ProfileColumnHeader from 'flavours/glitch/features/account/components/profile_column_header' ;
import HeaderContainer from 'flavours/glitch/features/account_timeline/containers/header_container' ;
import HeaderContainer from 'flavours/glitch/features/account_timeline/containers/header_container' ;
import LoadMore from 'flavours/glitch/components/load_more' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import MissingIndicator from 'flavours/glitch/components/missing_indicator' ;
import MissingIndicator from 'flavours/glitch/components/missing_indicator' ;
import ScrollableList from 'flavours/glitch/components/scrollable_list' ;
const mapStateToProps = ( state , props ) => ( {
const mapStateToProps = ( state , props ) => ( {
isAccount : ! ! state . getIn ( [ 'accounts' , props . params . accountId ] ) ,
isAccount : ! ! state . getIn ( [ 'accounts' , props . params . accountId ] ) ,
@ -58,10 +59,10 @@ export default class Followers extends ImmutablePureComponent {
}
}
}
}
handleLoadMore = ( e ) => {
handleLoadMore = debounce ( ( ) => {
e . preventDefault ( ) ;
e . preventDefault ( ) ;
this . props . dispatch ( expandFollowers ( this . props . params . accountId ) ) ;
this . props . dispatch ( expandFollowers ( this . props . params . accountId ) ) ;
}
} , 300 , { leading : true } ) ;
shouldUpdateScroll = ( prevRouterProps , { location } ) => {
shouldUpdateScroll = ( prevRouterProps , { location } ) => {
if ( ( ( ( prevRouterProps || { } ) . location || { } ) . state || { } ) . mastodonModalOpen ) return false ;
if ( ( ( ( prevRouterProps || { } ) . location || { } ) . state || { } ) . mastodonModalOpen ) return false ;
@ -83,8 +84,6 @@ export default class Followers extends ImmutablePureComponent {
) ;
) ;
}
}
let loadMore = null ;
if ( ! accountIds ) {
if ( ! accountIds ) {
return (
return (
< Column >
< Column >
@ -93,23 +92,25 @@ export default class Followers extends ImmutablePureComponent {
) ;
) ;
}
}
if ( hasMore ) {
const emptyMessage = < FormattedMessage id = 'account.followers.empty' defaultMessage = 'No one follows this user yet.' / > ;
loadMore = < LoadMore onClick = { this . handleLoadMore } / > ;
}
return (
return (
< Column ref = { this . setRef } >
< Column ref = { this . setRef } >
< ProfileColumnHeader onClick = { this . handleHeaderClick } / >
< ProfileColumnHeader onClick = { this . handleHeaderClick } / >
< ScrollContainer scrollKey = 'followers' shouldUpdateScroll = { this . shouldUpdateScroll } >
< HeaderContainer accountId = { this . props . params . accountId } hideTabs / >
< div className = 'scrollable' onScroll = { this . handleScroll } >
< div className = 'followers' >
< ScrollableList
< HeaderContainer accountId = { this . props . params . accountId } hideTabs / >
scrollKey = 'followers'
{ accountIds . map ( id => < AccountContainer key = { id } id = { id } withNote = { false } / > ) }
hasMore = { hasMore }
{ loadMore }
onLoadMore = { this . handleLoadMore }
< / d i v >
shouldUpdateScroll = { this . shouldUpdateScroll }
< / d i v >
emptyMessage = { emptyMessage }
< / S c r o l l C o n t a i n e r >
>
{ accountIds . map ( id =>
< AccountContainer key = { id } id = { id } withNote = { false } / >
) }
< / S c r o l l a b l e L i s t >
< / C o l u m n >
< / C o l u m n >
) ;
) ;
}
}