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

77 lines
2.2 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
2020-03-25 03:08:43 +00:00
import { injectIntl, FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
2020-04-08 02:06:59 +01:00
import debounce from 'lodash.debounce'
import { me } from '../initial_state'
2020-03-25 03:08:43 +00:00
import { fetchMutes, expandMutes } from '../actions/mutes'
2020-04-11 23:29:19 +01:00
import Account from '../components/account'
import Block from '../components/block'
import BlockHeading from '../components/block_heading'
2020-03-25 03:08:43 +00:00
import ScrollableList from '../components/scrollable_list'
class Mutes extends ImmutablePureComponent {
componentWillMount() {
this.props.onFetchMutes()
}
handleLoadMore = debounce(() => {
this.props.onExpandMutes()
2020-03-25 03:08:43 +00:00
}, 300, { leading: true })
render() {
const {
accountIds,
hasMore,
isLoading,
} = this.props
return (
<Block>
<BlockHeading title={<FormattedMessage id='navigation_bar.mutes' defaultMessage='Muted users' />} />
<ScrollableList
scrollKey='mutes'
onLoadMore={this.handleLoadMore}
hasMore={hasMore}
isLoading={isLoading}
emptyMessage={<FormattedMessage id='empty_column.mutes' defaultMessage="You haven't muted any users yet." />}
>
{
accountIds && accountIds.map((id) =>
<Account
key={`mutes-${id}`}
id={id}
compact
/>
)
}
</ScrollableList>
</Block>
2020-02-24 23:25:55 +00:00
)
}
}
const mapStateToProps = (state) => ({
accountIds: state.getIn(['user_lists', 'mutes', me, 'items']),
hasMore: !!state.getIn(['user_lists', 'mutes', me, 'next']),
isLoading: state.getIn(['user_lists', 'mutes', me, 'isLoading']),
})
const mapDispatchToProps = (dispatch) => ({
onFetchMutes: () => dispatch(fetchMutes()),
onExpandMutes: () => dispatch(expandMutes()),
})
Mutes.propTypes = {
accountIds: ImmutablePropTypes.list,
hasMore: PropTypes.bool,
isLoading: PropTypes.bool,
onExpandMutes: PropTypes.func.isRequired,
onFetchMutes: PropTypes.func.isRequired,
}
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(Mutes))