Skip to content

Commit 6f3d3f6

Browse files
sketchydroideOSBotify
authored andcommitted
Merge pull request #10545 from Expensify/marcaaron-useReportIDFromURLNotReportObject
Move report fetch to `ReportScreen` to populate `props.report` (cherry picked from commit 168f56e)
1 parent ede9ecf commit 6f3d3f6

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/pages/home/ReportScreen.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ const propTypes = {
6161

6262
/** Flag to check if the report actions data are loading */
6363
isLoadingReportActions: PropTypes.bool,
64+
65+
/** ID for the report */
66+
reportID: PropTypes.string,
6467
}),
6568

6669
/** Array of report actions for this report */
@@ -165,22 +168,31 @@ class ReportScreen extends React.Component {
165168
shouldShowLoader() {
166169
// This means there are no reportActions at all to display, but it is still in the process of loading the next set of actions.
167170
const isLoadingInitialReportActions = _.isEmpty(this.props.reportActions) && this.props.report.isLoadingReportActions;
168-
return !getReportID(this.props.route) || isLoadingInitialReportActions;
171+
return !getReportID(this.props.route) || isLoadingInitialReportActions || !this.props.report.reportID;
169172
}
170173

171174
/**
172175
* Persists the currently viewed report id
173176
*/
174177
storeCurrentlyViewedReport() {
175-
const reportID = getReportID(this.props.route);
176-
if (_.isNaN(reportID)) {
178+
const reportIDFromPath = getReportID(this.props.route);
179+
if (_.isNaN(reportIDFromPath)) {
177180
Report.handleInaccessibleReport();
178181
return;
179182
}
180183

181184
// Always reset the state of the composer view when the current reportID changes
182185
toggleReportActionComposeView(true);
183-
Report.updateCurrentlyViewedReportID(reportID);
186+
Report.updateCurrentlyViewedReportID(reportIDFromPath);
187+
188+
// It possible that we may not have the report object yet in Onyx yet e.g. we navigated to a URL for an accessible report that
189+
// is not stored locally yet. If props.report.reportID exists, then the report has been stored locally and nothing more needs to be done.
190+
// If it doesn't exist, then we fetch the report from the API.
191+
if (this.props.report.reportID) {
192+
return;
193+
}
194+
195+
Report.fetchChatReportsByIDs([reportIDFromPath], true);
184196
}
185197

186198
/**

src/pages/home/report/ReportActionsView.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ class ReportActionsView extends React.Component {
115115
Report.openReport(this.props.report.reportID);
116116
});
117117

118-
// If the reportID is not found then we have either not loaded this chat or the user is unable to access it.
119-
// We will attempt to fetch it and redirect if still not accessible.
120-
if (!this.props.report.reportID) {
121-
Report.fetchChatReportsByIDs([this.props.report.reportID], true);
122-
}
123118
Report.subscribeToReportTypingEvents(this.props.report.reportID);
124119
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', () => {
125120
if (!ReportActionComposeFocusManager.isFocused()) {

0 commit comments

Comments
 (0)