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 infinite loader when using attachments deeplink #24210

Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b55064f
Fix infinite loader when using attachments deeplink
huzaifa-99 Aug 7, 2023
caacb7a
Fix lint
huzaifa-99 Aug 7, 2023
8def131
Remove unnecessary return
huzaifa-99 Aug 7, 2023
9fedb1b
Updated import
huzaifa-99 Aug 7, 2023
eb01eb6
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Aug 7, 2023
1ab6710
Updated logic to check empty report actions in report attachments
huzaifa-99 Aug 7, 2023
c656d05
Updated attachments comparison in report attachments
huzaifa-99 Aug 7, 2023
efab87a
Updated logic to use existing report data
huzaifa-99 Aug 8, 2023
fce5252
Fix lint
huzaifa-99 Aug 8, 2023
aa83137
Use early return
huzaifa-99 Aug 8, 2023
0b39a14
Use early return
huzaifa-99 Aug 8, 2023
cd15863
Merge branch 'Expensify:main' into 23899-fix-image-preview-when-opene…
huzaifa-99 Aug 9, 2023
6ba0952
Updated open report logic in report attachments in case of deep link
huzaifa-99 Aug 9, 2023
8ffa396
Merge branch 'Expensify:main' into 23899-fix-image-preview-when-opene…
huzaifa-99 Aug 10, 2023
3b3b85e
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Aug 18, 2023
cfff37d
Moved empty reportActions check to platform files
huzaifa-99 Aug 18, 2023
2db59df
Added loader when report actions are loading
huzaifa-99 Aug 19, 2023
490277f
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Aug 21, 2023
55ba828
Use existing util to get report attachments
huzaifa-99 Aug 21, 2023
ae9df4a
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Aug 28, 2023
07bf87d
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Sep 11, 2023
00585f5
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Oct 2, 2023
0b7b5be
Fix lint
huzaifa-99 Oct 2, 2023
40fdf86
Use report metadata for loading state
huzaifa-99 Oct 4, 2023
865388a
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Oct 24, 2023
2ece4e7
Fix merge conflict
huzaifa-99 Oct 24, 2023
9086775
Get report attachment if not in report actions
huzaifa-99 Oct 24, 2023
6c40270
Fix loader when actions are loading
huzaifa-99 Oct 25, 2023
b112dab
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Oct 25, 2023
7b4bd67
Replaced isLoadingReportActions with isLoadingInitialReportActions
huzaifa-99 Oct 25, 2023
f386072
Fix lint
huzaifa-99 Oct 25, 2023
6221126
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Dec 13, 2023
3f6180d
Fix lint
huzaifa-99 Dec 13, 2023
b756452
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Dec 14, 2023
41e66b4
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Dec 20, 2023
d46665d
Merge branch 'main' into 23899-fix-image-preview-when-opened-with-dee…
huzaifa-99 Jan 9, 2024
ffb750b
Fix lint
huzaifa-99 Jan 9, 2024
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
2 changes: 1 addition & 1 deletion src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function AttachmentModal(props) {
onCloseButtonPress={closeModal}
/>
<View style={styles.imageModalImageCenterContainer}>
{!_.isEmpty(props.report) ? (
{!_.isEmpty(props.report) && !props.report.isLoadingReportActions ? (
<AttachmentCarousel
report={props.report}
onNavigate={onNavigate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ import Navigation from '../../../libs/Navigation/Navigation';
* @returns {{attachments: Array, initialPage: Number, initialItem: Object, initialActiveSource: String}}
*/
function extractAttachmentsFromReport(report, reportActions, source) {
// Even an empty chat will have the 'created' report action, if its not there
// then we are coming from a deep link and actions are not yet loaded. We should
// wait until actions load.
if (_.isEmpty(reportActions)) {
return {
attachments: [],
initialPage: 0,
initialItem: undefined,
initialActiveSource: null,
};
}

const actions = [ReportActionsUtils.getParentReportAction(report), ...ReportActionsUtils.getSortedReportActions(_.values(reportActions))];
let attachments = [];

Expand Down Expand Up @@ -44,7 +56,7 @@ function extractAttachmentsFromReport(report, reportActions, source) {

attachments = attachments.reverse();

const initialPage = _.findIndex(attachments, (a) => a.source === source);
const initialPage = _.findIndex(attachments, (a) => a.source.includes(source));
if (initialPage === -1) {
Navigation.dismissModal();
return {
Expand Down
10 changes: 10 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ function getReportAction(reportID, reportActionID) {
return lodashGet(allReportActions, [reportID, reportActionID], {});
}

/**
*
* @param {String} reportID
* @returns {Object}
*/
function getReportActions(reportID) {
return lodashGet(allReportActions, [reportID], {});
}

/**
* @returns {string}
*/
Expand Down Expand Up @@ -593,4 +602,5 @@ export {
isWhisperAction,
isPendingRemove,
getReportAction,
getReportActions,
};
63 changes: 58 additions & 5 deletions src/pages/home/report/ReportAttachments.js
huzaifa-99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from 'react';
import React, {useEffect, useState} from 'react';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import AttachmentModal from '../../../components/AttachmentModal';
import Navigation from '../../../libs/Navigation/Navigation';
import * as ReportUtils from '../../../libs/ReportUtils';
import * as Report from '../../../libs/actions/Report';
import * as ReportActionUtils from '../../../libs/ReportActionsUtils';
import ROUTES from '../../../ROUTES';
import ONYXKEYS from '../../../ONYXKEYS';
import reportPropTypes from '../../reportPropTypes';

const propTypes = {
/** Navigation route context info provided by react navigation */
Expand All @@ -17,18 +22,61 @@ const propTypes = {
source: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,

/** The report that has this attachment */
report: reportPropTypes,
};

const defaultProps = {
report: {},
};

/**
* Get the currently viewed report ID as number
*
* @param {Object} route
* @param {Object} route.params
* @param {String} route.params.reportID
* @returns {String}
*/
function getReportID(route) {
return String(lodashGet(route, 'params.reportID', null));
}

function ReportAttachments(props) {
const reportID = _.get(props, ['route', 'params', 'reportID']);
const report = ReportUtils.getReport(reportID);
const source = decodeURI(_.get(props, ['route', 'params', 'source']));
const [initialReport, setInitialReport] = useState(props.report);

huzaifa-99 marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
if (!props.report.reportID || reportID === props.report.reportID) return;
setInitialReport(props.report);
}, [reportID, props.report]);

/** This effects handles 2x cases when report attachments are opened with deep link */
useEffect(() => {
// Case 1 - if we are logged out and use the deep link for attachments and then login, then
// the report will not have reportID yet, and we wouldn't have loaded report and report actions
// data yet. call openReport to get both report and report actions data
if (!initialReport.reportID) {
Report.openReport(reportID);
return;
}

// Case 2 - if we are already logged in and the report actions are not already loading and
// report has no report actions (even an empty chat will have the 'created' report action),
// then we are on a page other than report screen. Now call openReport to get report actions
// since we dont have them in onyx.
const reportActions = ReportActionUtils.getReportActions(initialReport.reportID);
if (initialReport.isLoadingReportActions || !_.isEmpty(reportActions)) return;
huzaifa-99 marked this conversation as resolved.
Show resolved Hide resolved
Report.openReport(reportID);
}, [initialReport, reportID]);

return (
<AttachmentModal
allowDownload
defaultOpen
report={report}
report={props.report}
source={source}
onModalHide={() => Navigation.dismissModal(reportID)}
onCarouselAttachmentChange={(attachment) => {
Expand All @@ -40,6 +88,11 @@ function ReportAttachments(props) {
}

ReportAttachments.propTypes = propTypes;
ReportAttachments.defaultProps = defaultProps;
ReportAttachments.displayName = 'ReportAttachments';

export default ReportAttachments;
export default withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`,
},
})(ReportAttachments);
Loading