2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
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 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-04-17 06:35:46 +01:00
|
|
|
const mapStateToProps = (state, { account, commentsOnly = false }) => {
|
2020-03-04 22:26:01 +00:00
|
|
|
const accountId = !!account ? account.getIn(['id'], null) : -1
|
2019-08-13 16:54:29 +01:00
|
|
|
|
2020-04-17 06:35:46 +01:00
|
|
|
const path = commentsOnly ? `${accountId}:comments_only` : accountId
|
|
|
|
|
2019-08-13 16:54:29 +01:00
|
|
|
return {
|
|
|
|
accountId,
|
|
|
|
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], emptyList),
|
2020-04-17 06:35:46 +01:00
|
|
|
featuredStatusIds: commentsOnly ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], emptyList),
|
2020-07-29 21:49:18 +01:00
|
|
|
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading'], true),
|
2019-08-13 16:54:29 +01:00
|
|
|
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,
|
2020-04-17 06:35:46 +01:00
|
|
|
commentsOnly: PropTypes.bool,
|
2019-08-13 16:54:29 +01:00
|
|
|
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-04-17 06:35:46 +01:00
|
|
|
const { accountId, commentsOnly } = this.props
|
2019-08-13 16:54:29 +01:00
|
|
|
|
|
|
|
if (accountId && accountId !== -1) {
|
2020-04-17 06:35:46 +01:00
|
|
|
if (!commentsOnly) {
|
2020-03-04 22:26:01 +00:00
|
|
|
this.props.dispatch(expandAccountFeaturedTimeline(accountId))
|
2019-08-13 16:54:29 +01:00
|
|
|
}
|
|
|
|
|
2020-04-17 06:35:46 +01:00
|
|
|
this.props.dispatch(expandAccountTimeline(accountId, { commentsOnly }))
|
2019-08-13 16:54:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 23:25:55 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2020-04-17 06:35:46 +01:00
|
|
|
if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId) || nextProps.commentsOnly !== this.props.commentsOnly) {
|
|
|
|
if (!nextProps.commentsOnly) {
|
2020-03-04 22:26:01 +00:00
|
|
|
this.props.dispatch(expandAccountFeaturedTimeline(nextProps.accountId))
|
2019-08-13 16:54:29 +01:00
|
|
|
}
|
|
|
|
|
2020-04-17 06:35:46 +01:00
|
|
|
this.props.dispatch(expandAccountTimeline(nextProps.accountId, { commentsOnly: nextProps.commentsOnly }))
|
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,
|
2020-04-17 06:35:46 +01:00
|
|
|
commentsOnly: this.props.commentsOnly
|
2020-03-04 22:26:01 +00:00
|
|
|
}))
|
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 {
|
|
|
|
statusIds,
|
|
|
|
featuredStatusIds,
|
|
|
|
isLoading,
|
|
|
|
hasMore,
|
|
|
|
intl
|
|
|
|
} = this.props
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|