Skip to content

Commit

Permalink
refactor: ReportActionCompose stop relying on global modal state to p…
Browse files Browse the repository at this point in the history
…revent bugs

Unwanted side effects coming from `componentDidUpdate` and global `modal.isVisible`

Details: Expensify#1913 (comment)
  • Loading branch information
kidroca committed Mar 26, 2021
1 parent 2b0674b commit b33b759
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ const propTypes = {
// The ID of the report actions will be created for
reportID: PropTypes.number.isRequired,

// Details about any modals being used
modal: PropTypes.shape({
// Indicates if there is a modal currently visible or not
isVisible: PropTypes.bool,
}),

// The report currently being looked at
report: PropTypes.shape({

Expand All @@ -48,7 +42,6 @@ const propTypes = {

const defaultProps = {
comment: '',
modal: {},
};

class ReportActionCompose extends React.Component {
Expand Down Expand Up @@ -78,11 +71,8 @@ class ReportActionCompose extends React.Component {
this.comment = this.props.comment;
}

// When any modal goes from visible to hidden or when the report ID changes, bring focus to the compose field
if (
(prevProps.modal.isVisible && !this.props.modal.isVisible)
|| (prevProps.reportID !== this.props.reportID)
) {
// When the report ID changes, bring focus to the compose field
if (prevProps.reportID !== this.props.reportID) {
this.setIsFocused(true);
}
}
Expand Down Expand Up @@ -204,6 +194,7 @@ class ReportActionCompose extends React.Component {
>
<AttachmentModal
title="Upload Attachment"
onModalHide={() => this.setIsFocused(true)}
onConfirm={(file) => {
addAction(this.props.reportID, '', file);
this.setTextInputShouldClear(false);
Expand Down Expand Up @@ -314,9 +305,6 @@ export default compose(
comment: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`,
},
modal: {
key: ONYXKEYS.MODAL,
},
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
},
Expand Down

0 comments on commit b33b759

Please sign in to comment.