Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent dropping files in the drop zone if the attachment modal is active #18624

Merged
merged 2 commits into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class ReportActionCompose extends React.Component {
this.showPopoverMenu = this.showPopoverMenu.bind(this);
this.comment = props.comment;
this.setShouldBlockEmojiCalcToFalse = this.setShouldBlockEmojiCalcToFalse.bind(this);
this.attachmentPreviewClosed = this.attachmentPreviewClosed.bind(this);

// React Native will retain focus on an input for native devices but web/mWeb behave differently so we have some focus management
// code that will refocus the compose input after a user closes a modal or some other actions, see usage of ReportActionComposeFocusManager
Expand Down Expand Up @@ -214,6 +215,7 @@ class ReportActionCompose extends React.Component {
isEmojiPickerLarge: false,
composerHeight: 0,
hasExceededMaxCommentLength: false,
isAttachmentPreviewActive: false,
};
}

Expand Down Expand Up @@ -747,6 +749,14 @@ class ReportActionCompose extends React.Component {
return true;
}

/**
* Event handler to update the state after the attachment preview is closed.
*/
attachmentPreviewClosed() {
this.setShouldBlockEmojiCalcToFalse();
this.setState({isAttachmentPreviewActive: false});
}

render() {
const reportParticipants = _.without(lodashGet(this.props.report, 'participants', []), this.props.currentUserPersonalDetails.login);
const participantsWithoutExpensifyEmails = _.difference(reportParticipants, CONST.EXPENSIFY_EMAILS);
Expand Down Expand Up @@ -787,7 +797,7 @@ class ReportActionCompose extends React.Component {
<AttachmentModal
headerTitle={this.props.translate('reportActionCompose.sendAttachment')}
onConfirm={this.addAttachment}
onModalHide={this.setShouldBlockEmojiCalcToFalse}
onModalHide={this.attachmentPreviewClosed}
>
{({displayFileInModal}) => (
<>
Expand Down Expand Up @@ -892,12 +902,16 @@ class ReportActionCompose extends React.Component {
}}
onDrop={(e) => {
e.preventDefault();
if (this.state.isAttachmentPreviewActive) {
this.setState({isDraggingOver: false});
return;
}

const file = lodashGet(e, ['dataTransfer', 'files', 0]);

displayFileInModal(file);

this.setState({isDraggingOver: false});
this.setState({isAttachmentPreviewActive: true, isDraggingOver: false});
}}
disabled={this.props.disabled}
>
Expand Down