2022-02-24 18:34:33 -05:00
import PropTypes from 'prop-types' ;
2023-05-23 11:15:17 -04:00
import { PureComponent } from 'react' ;
2022-02-24 18:34:33 -05:00
import { FormattedMessage } from 'react-intl' ;
2023-05-23 11:15:17 -04:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2022-02-24 18:34:33 -05:00
import { connect } from 'react-redux' ;
2023-05-23 11:15:17 -04:00
2022-04-06 16:53:29 -04:00
import { debounce } from 'lodash' ;
2023-05-23 11:15:17 -04:00
import { fetchTrendingStatuses , expandTrendingStatuses } from 'mastodon/actions/trends' ;
2022-10-09 00:08:37 -04:00
import DismissableBanner from 'mastodon/components/dismissable_banner' ;
2023-05-23 11:15:17 -04:00
import StatusList from 'mastodon/components/status_list' ;
2022-02-24 18:34:33 -05:00
const mapStateToProps = state => ( {
statusIds : state . getIn ( [ 'status_lists' , 'trending' , 'items' ] ) ,
isLoading : state . getIn ( [ 'status_lists' , 'trending' , 'isLoading' ] , true ) ,
2022-04-06 16:53:29 -04:00
hasMore : ! ! state . getIn ( [ 'status_lists' , 'trending' , 'next' ] ) ,
2022-02-24 18:34:33 -05:00
} ) ;
2023-05-23 04:52:27 -04:00
class Statuses extends PureComponent {
2022-02-24 18:34:33 -05:00
static propTypes = {
statusIds : ImmutablePropTypes . list ,
isLoading : PropTypes . bool ,
2022-04-06 16:53:29 -04:00
hasMore : PropTypes . bool ,
2022-02-24 18:34:33 -05:00
multiColumn : PropTypes . bool ,
dispatch : PropTypes . func . isRequired ,
} ;
componentDidMount ( ) {
const { dispatch } = this . props ;
dispatch ( fetchTrendingStatuses ( ) ) ;
}
2022-04-06 16:53:29 -04:00
handleLoadMore = debounce ( ( ) => {
const { dispatch } = this . props ;
dispatch ( expandTrendingStatuses ( ) ) ;
2023-01-29 19:45:35 -05:00
} , 300 , { leading : true } ) ;
2022-04-06 16:53:29 -04:00
2022-02-24 18:34:33 -05:00
render ( ) {
2022-04-06 16:53:29 -04:00
const { isLoading , hasMore , statusIds , multiColumn } = this . props ;
2022-02-24 18:34:33 -05:00
const emptyMessage = < FormattedMessage id = 'empty_column.explore_statuses' defaultMessage = 'Nothing is trending right now. Check back later!' / > ;
return (
2022-10-09 00:08:37 -04:00
< >
< DismissableBanner id = 'explore/statuses' >
< FormattedMessage id = 'dismissable_banner.explore_statuses' defaultMessage = 'These posts from this and other servers in the decentralized network are gaining traction on this server right now.' / >
< / DismissableBanner >
< StatusList
trackScroll
statusIds = { statusIds }
scrollKey = 'explore-statuses'
hasMore = { hasMore }
isLoading = { isLoading }
onLoadMore = { this . handleLoadMore }
emptyMessage = { emptyMessage }
bindToDocument = { ! multiColumn }
withCounters
/ >
< / >
2022-02-24 18:34:33 -05:00
) ;
}
}
2023-03-23 22:17:53 -04:00
export default connect ( mapStateToProps ) ( Statuses ) ;