From d6b8948191a564184039f12b753a24814bab9be7 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Tue, 21 Jul 2020 22:27:48 -0500 Subject: [PATCH] Fixed issue with loading context, comments from Status feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixed: - issue with loading context, comments from Status feature by loading in feature not child • Added: - check for if ancestor status exists in StatusContainer --- app/javascript/gabsocial/components/status.js | 2 +- .../gabsocial/containers/status_container.js | 2 +- app/javascript/gabsocial/features/status.js | 25 ++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/javascript/gabsocial/components/status.js b/app/javascript/gabsocial/components/status.js index b606c8d6..fb2c7d36 100644 --- a/app/javascript/gabsocial/components/status.js +++ b/app/javascript/gabsocial/components/status.js @@ -173,7 +173,7 @@ class Status extends ImmutablePureComponent { // Compensate height changes componentDidUpdate(prevProps, prevState, snapshot) { // timeline lazy loading comments - if (!prevState.loadedComments && this.state.loadedComments && this.props.status && !this.props.isChild) { + if (!prevState.loadedComments && this.state.loadedComments && this.props.status && !this.props.isChild && this.props.contextType !== 'feature') { const commentCount = this.props.status.get('replies_count') if (this.props.isComment && !this.props.ancestorStatus) { this.props.onFetchContext(this.props.status.get('id')) diff --git a/app/javascript/gabsocial/containers/status_container.js b/app/javascript/gabsocial/containers/status_container.js index 4e92ae33..32830816 100644 --- a/app/javascript/gabsocial/containers/status_container.js +++ b/app/javascript/gabsocial/containers/status_container.js @@ -152,7 +152,7 @@ const makeMapStateToProps = () => { ancestorStatus = getStatus(state, { id: ancestorStatusId, }) - descendantsIds = getDescendants(state, ancestorStatus, statusId) + if (!!ancestorStatus) descendantsIds = getDescendants(state, ancestorStatus, statusId) } } diff --git a/app/javascript/gabsocial/features/status.js b/app/javascript/gabsocial/features/status.js index 517ea236..029a30d7 100644 --- a/app/javascript/gabsocial/features/status.js +++ b/app/javascript/gabsocial/features/status.js @@ -1,6 +1,10 @@ import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' -import { fetchStatus } from '../actions/statuses' +import { + fetchStatus, + fetchComments, + fetchContext, +} from '../actions/statuses' import StatusContainer from '../containers/status_container' import ColumnIndicator from '../components/column_indicator' @@ -14,6 +18,8 @@ const mapStateToProps = (state, props) => { const mapDispatchToProps = (dispatch) => ({ onFetchStatus: (id) => dispatch(fetchStatus(id)), + onFetchContext: (id) => dispatch(fetchContext(id)), + onFetchComments: (id) => dispatch(fetchComments(id)), }) export default @@ -21,7 +27,9 @@ export default class Status extends ImmutablePureComponent { static propTypes = { + onFetchContext: PropTypes.func.isRequired, onFetchStatus: PropTypes.func.isRequired, + onFetchComments: PropTypes.func.isRequired, params: PropTypes.object, status: ImmutablePropTypes.map, } @@ -36,6 +44,21 @@ class Status extends ImmutablePureComponent { this.props.onFetchStatus(statusId) } + componentDidUpdate(prevProps) { + const { status } = this.props + + if (prevProps.status !== status && !!status) { + 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')) + } + } + } + render() { const { status } = this.props