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-05-03 06:22:49 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-07-22 04:27:48 +01:00
|
|
|
import {
|
|
|
|
fetchStatus,
|
|
|
|
fetchComments,
|
|
|
|
fetchContext,
|
|
|
|
} from '../actions/statuses'
|
2020-04-29 23:32:49 +01:00
|
|
|
import StatusContainer from '../containers/status_container'
|
2020-07-28 21:11:51 +01:00
|
|
|
import StatusPlaceholder from '../components/placeholder/status_placeholder'
|
2020-05-03 06:22:49 +01:00
|
|
|
|
|
|
|
class Status extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const statusId = this.props.id || this.props.params.statusId
|
|
|
|
this.props.onFetchStatus(statusId)
|
2020-07-22 05:44:35 +01:00
|
|
|
|
|
|
|
if (!!this.props.status) {
|
|
|
|
this.shouldFetchStatusParts(this.props.status)
|
|
|
|
}
|
2020-05-03 06:22:49 +01:00
|
|
|
}
|
2020-04-29 23:32:49 +01:00
|
|
|
|
2020-07-22 04:27:48 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { status } = this.props
|
|
|
|
|
|
|
|
if (prevProps.status !== status && !!status) {
|
2020-07-22 05:44:35 +01:00
|
|
|
this.shouldFetchStatusParts(status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldFetchStatusParts = (status) => {
|
|
|
|
if (!status) return
|
|
|
|
|
|
|
|
const isComment = !!status.get('in_reply_to_account_id')
|
|
|
|
const hasComments = status.get('replies_count') > 0
|
|
|
|
|
|
|
|
if (isComment) {
|
|
|
|
this.props.onFetchContext(status.get('id'))
|
|
|
|
} else if (!isComment && hasComments) {
|
|
|
|
this.props.onFetchComments(status.get('id'))
|
2020-07-22 04:27:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 23:32:49 +01:00
|
|
|
render() {
|
2020-05-03 06:22:49 +01:00
|
|
|
const { status } = this.props
|
2020-05-05 06:16:01 +01:00
|
|
|
|
2020-05-03 06:22:49 +01:00
|
|
|
if (!status) {
|
2020-07-28 21:11:51 +01:00
|
|
|
return <StatusPlaceholder />
|
2020-05-03 06:22:49 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 23:32:49 +01:00
|
|
|
return (
|
2020-05-04 19:44:37 +01:00
|
|
|
<StatusContainer {...this.props} contextType='feature' />
|
2020-04-29 23:32:49 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => {
|
|
|
|
const statusId = props.id || props.params.statusId
|
|
|
|
|
|
|
|
return {
|
2020-12-20 17:27:24 +00:00
|
|
|
statusId,
|
2020-08-19 01:22:15 +01:00
|
|
|
status: state.getIn(['statuses', statusId]),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onFetchStatus: (id) => dispatch(fetchStatus(id)),
|
|
|
|
onFetchContext: (id) => dispatch(fetchContext(id)),
|
|
|
|
onFetchComments: (id) => dispatch(fetchComments(id)),
|
|
|
|
})
|
|
|
|
|
|
|
|
Status.propTypes = {
|
|
|
|
onFetchContext: PropTypes.func.isRequired,
|
|
|
|
onFetchStatus: PropTypes.func.isRequired,
|
|
|
|
onFetchComments: PropTypes.func.isRequired,
|
|
|
|
params: PropTypes.object,
|
|
|
|
status: ImmutablePropTypes.map,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Status)
|