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: Don't add new content an already opened carousel #18651

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
35 changes: 11 additions & 24 deletions src/components/AttachmentCarousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,13 @@ class AttachmentCarousel extends React.Component {
this.updateZoomState = this.updateZoomState.bind(this);
this.toggleArrowsVisibility = this.toggleArrowsVisibility.bind(this);

this.state = {
attachments: [],
source: this.props.source,
shouldShowArrow: this.canUseTouchScreen,
containerWidth: 0,
isZoomed: false,
};
this.state = this.makeInitialState();
}

componentDidMount() {
this.makeStateWithReports();
this.autoHideArrow();
}

componentDidUpdate(prevProps) {
const previousReportActionsCount = _.size(prevProps.reportActions);
const currentReportActionsCount = _.size(this.props.reportActions);
if (previousReportActionsCount === currentReportActionsCount) {
return;
}

this.makeStateWithReports();
}

/**
* Helps to navigate between next/previous attachments
* @param {Object} attachmentItem
Expand Down Expand Up @@ -173,9 +156,10 @@ class AttachmentCarousel extends React.Component {
}

/**
* Map report actions to attachment items
* Map report actions to attachment items and sets the initial carousel state
* @returns {{page: Number, attachments: Array, shouldShowArrow: Boolean, containerWidth: Number, isZoomed: Boolean}}
*/
makeStateWithReports() {
makeInitialState() {
let page = 0;
const actions = ReportActionsUtils.getSortedReportActions(_.values(this.props.reportActions), true);

Expand All @@ -197,18 +181,21 @@ class AttachmentCarousel extends React.Component {
// Update the image URL so the images can be accessed depending on the config environment.
// Eg: while using Ngrok the image path is from an Ngrok URL and not an Expensify URL.
const source = tryResolveUrlFromApiRoot(originalSource);
if (source === this.state.source) {
if (source === this.props.source) {
page = attachments.length;
}

attachments.push({source, file: {name}});
}
});

this.setState({
return {
page,
attachments,
});
shouldShowArrow: this.canUseTouchScreen,
containerWidth: 0,
isZoomed: false,
};
}

/**
Expand Down Expand Up @@ -243,7 +230,7 @@ class AttachmentCarousel extends React.Component {
const page = entry.index;
const {source, file} = this.getAttachment(entry.item);
this.props.onNavigate({source: addEncryptedAuthTokenToURL(source), file});
this.setState({page, source, isZoomed: false});
this.setState({page, isZoomed: false});
}

/**
Expand Down