2022-02-24 23:34:33 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import StatusList from 'mastodon/components/status_list';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { connect } from 'react-redux';
|
2022-04-06 20:53:29 +00:00
|
|
|
import { fetchTrendingStatuses, expandTrendingStatuses } from 'mastodon/actions/trends';
|
|
|
|
import { debounce } from 'lodash';
|
2022-02-24 23:34:33 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
statusIds: state.getIn(['status_lists', 'trending', 'items']),
|
|
|
|
isLoading: state.getIn(['status_lists', 'trending', 'isLoading'], true),
|
2022-04-06 20:53:29 +00:00
|
|
|
hasMore: !!state.getIn(['status_lists', 'trending', 'next']),
|
2022-02-24 23:34:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
class Statuses extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
statusIds: ImmutablePropTypes.list,
|
|
|
|
isLoading: PropTypes.bool,
|
2022-04-06 20:53:29 +00:00
|
|
|
hasMore: PropTypes.bool,
|
2022-02-24 23:34:33 +00:00
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(fetchTrendingStatuses());
|
|
|
|
}
|
|
|
|
|
2022-04-06 20:53:29 +00:00
|
|
|
handleLoadMore = debounce(() => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(expandTrendingStatuses());
|
|
|
|
}, 300, { leading: true })
|
|
|
|
|
2022-02-24 23:34:33 +00:00
|
|
|
render () {
|
2022-04-06 20:53:29 +00:00
|
|
|
const { isLoading, hasMore, statusIds, multiColumn } = this.props;
|
2022-02-24 23:34:33 +00:00
|
|
|
|
|
|
|
const emptyMessage = <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StatusList
|
|
|
|
trackScroll
|
|
|
|
statusIds={statusIds}
|
|
|
|
scrollKey='explore-statuses'
|
2022-04-06 20:53:29 +00:00
|
|
|
hasMore={hasMore}
|
2022-02-24 23:34:33 +00:00
|
|
|
isLoading={isLoading}
|
2022-04-06 20:53:29 +00:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2022-02-24 23:34:33 +00:00
|
|
|
emptyMessage={emptyMessage}
|
|
|
|
bindToDocument={!multiColumn}
|
|
|
|
withCounters
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|