gab-social/app/javascript/gabsocial/features/liked_statuses.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-03-02 22:26:25 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import { FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
2020-04-08 02:06:59 +01:00
import debounce from 'lodash.debounce'
2020-03-04 23:08:08 +00:00
import { fetchFavoritedStatuses, expandFavoritedStatuses } from '../actions/favorites'
import { meUsername } from '../initial_state'
import StatusList from '../components/status_list'
import ColumnIndicator from '../components/column_indicator'
const mapStateToProps = (state, { params: { username } }) => {
return {
isMyAccount: (username.toLowerCase() === meUsername.toLowerCase()),
2020-02-29 15:42:47 +00:00
statusIds: state.getIn(['status_lists', 'favorites', 'items']),
isLoading: state.getIn(['status_lists', 'favorites', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'favorites', 'next']),
2020-03-02 22:26:25 +00:00
}
}
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps)
2020-03-24 04:39:12 +00:00
class LikedStatuses extends ImmutablePureComponent {
static propTypes = {
dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list.isRequired,
hasMore: PropTypes.bool,
isLoading: PropTypes.bool,
isMyAccount: PropTypes.bool.isRequired,
2020-03-02 22:26:25 +00:00
}
2020-03-02 22:26:25 +00:00
componentWillMount() {
this.props.dispatch(fetchFavoritedStatuses())
}
handleLoadMore = debounce(() => {
2020-03-02 22:26:25 +00:00
this.props.dispatch(expandFavoritedStatuses())
}, 300, { leading: true })
2020-03-02 22:26:25 +00:00
render() {
const { statusIds, hasMore, isLoading, isMyAccount } = this.props
if (!isMyAccount) {
2020-03-02 22:26:25 +00:00
return <ColumnIndicator type='missing' />
}
return (
2020-03-02 22:26:25 +00:00
<StatusList
statusIds={statusIds}
2020-03-24 04:39:12 +00:00
scrollKey='liked_statuses'
2020-03-02 22:26:25 +00:00
hasMore={hasMore}
isLoading={isLoading}
onLoadMore={this.handleLoadMore}
2020-03-24 04:39:12 +00:00
emptyMessage={<FormattedMessage id='empty_column.liked_statuses' defaultMessage="You don't have any liked gabs yet. When you like one, it will show up here." />}
2020-03-02 22:26:25 +00:00
/>
)
}
}