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

64 lines
2.0 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
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'
2020-03-24 04:39:12 +00:00
class LikedStatuses extends ImmutablePureComponent {
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
/>
)
}
}
const mapStateToProps = (state, { params: { username } }) => ({
isMyAccount: (username.toLowerCase() === meUsername.toLowerCase()),
statusIds: state.getIn(['status_lists', 'favorites', 'items']),
isLoading: state.getIn(['status_lists', 'favorites', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'favorites', 'next']),
})
LikedStatuses.propTypes = {
dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list.isRequired,
hasMore: PropTypes.bool,
isLoading: PropTypes.bool,
isMyAccount: PropTypes.bool.isRequired,
}
export default connect(mapStateToProps)(LikedStatuses)