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

106 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-03-04 22:26:01 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { List as ImmutableList } from 'immutable'
import { injectIntl, defineMessages } from 'react-intl'
2020-03-27 15:29:52 +00:00
import { expandAccountFeaturedTimeline, expandAccountTimeline } from '../actions/timelines'
import { fetchAccountIdentityProofs } from '../actions/identity_proofs'
import StatusList from '../components/status_list'
2019-08-13 16:54:29 +01:00
const messages = defineMessages({
2020-03-04 22:26:01 +00:00
empty: { id: 'empty_column.account_timeline', defaultMessage: 'No gabs here!' },
})
const emptyList = ImmutableList()
2019-08-13 16:54:29 +01:00
2020-03-04 22:26:01 +00:00
const mapStateToProps = (state, { account, withReplies = false }) => {
const accountId = !!account ? account.getIn(['id'], null) : -1
2019-08-13 16:54:29 +01:00
2020-03-04 22:26:01 +00:00
const path = withReplies ? `${accountId}:with_replies` : accountId
2019-08-13 16:54:29 +01:00
return {
accountId,
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], emptyList),
featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], emptyList),
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
2020-03-04 22:26:01 +00:00
}
}
2019-08-13 16:54:29 +01:00
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps)
2019-08-13 16:54:29 +01:00
@injectIntl
class AccountTimeline extends ImmutablePureComponent {
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list,
featuredStatusIds: ImmutablePropTypes.list,
isLoading: PropTypes.bool,
hasMore: PropTypes.bool,
withReplies: PropTypes.bool,
intl: PropTypes.object.isRequired,
2020-03-04 22:26:01 +00:00
}
2019-08-13 16:54:29 +01:00
2020-02-24 23:25:55 +00:00
componentWillMount() {
2020-03-04 22:26:01 +00:00
const { accountId, withReplies } = this.props
2019-08-13 16:54:29 +01:00
if (accountId && accountId !== -1) {
2020-03-04 22:26:01 +00:00
this.props.dispatch(fetchAccountIdentityProofs(accountId))
2019-08-13 16:54:29 +01:00
if (!withReplies) {
2020-03-04 22:26:01 +00:00
this.props.dispatch(expandAccountFeaturedTimeline(accountId))
2019-08-13 16:54:29 +01:00
}
2020-03-04 22:26:01 +00:00
this.props.dispatch(expandAccountTimeline(accountId, { withReplies }))
2019-08-13 16:54:29 +01:00
}
}
2020-02-24 23:25:55 +00:00
componentWillReceiveProps(nextProps) {
2019-08-13 16:54:29 +01:00
if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId) || nextProps.withReplies !== this.props.withReplies) {
2020-03-04 22:26:01 +00:00
this.props.dispatch(fetchAccountIdentityProofs(nextProps.accountId))
2019-08-13 16:54:29 +01:00
if (!nextProps.withReplies) {
2020-03-04 22:26:01 +00:00
this.props.dispatch(expandAccountFeaturedTimeline(nextProps.accountId))
2019-08-13 16:54:29 +01:00
}
2020-03-04 22:26:01 +00:00
this.props.dispatch(expandAccountTimeline(nextProps.accountId, { withReplies: nextProps.withReplies }))
2019-08-13 16:54:29 +01:00
}
}
handleLoadMore = maxId => {
if (this.props.accountId && this.props.accountId !== -1) {
2020-03-04 22:26:01 +00:00
this.props.dispatch(expandAccountTimeline(this.props.accountId, {
maxId,
withReplies: this.props.withReplies
}))
2019-08-13 16:54:29 +01:00
}
}
2020-02-24 23:25:55 +00:00
render() {
2020-03-04 22:26:01 +00:00
const {
account,
statusIds,
featuredStatusIds,
isLoading,
hasMore,
intl
} = this.props
if (!account) return null
2019-08-13 16:54:29 +01:00
return (
2020-02-24 23:25:55 +00:00
<StatusList
scrollKey='account_timeline'
statusIds={statusIds}
featuredStatusIds={featuredStatusIds}
isLoading={isLoading}
hasMore={hasMore}
onLoadMore={this.handleLoadMore}
2020-03-04 22:26:01 +00:00
emptyMessage={intl.formatMessage(messages.empty)}
2020-02-24 23:25:55 +00:00
/>
2020-03-04 22:26:01 +00:00
)
2019-08-13 16:54:29 +01:00
}
}