Skip to content

Commit

Permalink
Merge pull request #1790 from Expensify/marcaaron-fixRundefined
Browse files Browse the repository at this point in the history
Fix /r/undefined issue
  • Loading branch information
NikkiWines authored Mar 17, 2021
2 parents c5cb507 + 4ab0d2b commit 87c1540
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/libs/Navigation/AppNavigator/MainDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const MainDrawerNavigator = props => (
<Drawer.Screen
name="Report"
component={ReportScreen}

// Providing an empty string here will ensure that the ReportScreen does not show as '/r/undefined'
// eslint-disable-next-line react/jsx-props-no-multi-spaces
initialParams={{reportID: ''}}
options={{
cardStyle: styles.navigationScreenCardStyle,
headerShown: false,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/NavigationRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class NavigationRoot extends Component {
const path = getPathFromState(state, linkingConfig.config);
if (path.includes(ROUTES.REPORT)) {
const reportID = Number(_.last(path.split('/')));
if (!_.isNaN(reportID)) {
if (reportID && !_.isNaN(reportID)) {
updateCurrentlyViewedReportID(reportID);
}
}
Expand Down
22 changes: 8 additions & 14 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ Onyx.connect({
},
});

let currentURL;
Onyx.connect({
key: ONYXKEYS.CURRENT_URL,
callback: val => currentURL = val,
});

let lastViewedReportID;
Onyx.connect({
key: ONYXKEYS.CURRENTLY_VIEWED_REPORTID,
Expand Down Expand Up @@ -551,16 +545,16 @@ function fetchActions(reportID, offset) {
function fetchAll(shouldRedirectToReport = true, shouldRecordHomePageTiming = false) {
fetchChatReports()
.then((reportIDs) => {
if (shouldRedirectToReport && !currentURL.includes(ROUTES.REPORT)) {
// Redirect to either the last viewed report ID or the first report ID from our report collection
if (shouldRedirectToReport) {
// Update currentlyViewedReportID to be our first reportID from our report collection if we don't have
// one already.
if (lastViewedReportID) {
Onyx.set(ONYXKEYS.CURRENTLY_VIEWED_REPORTID, String(lastViewedReportID));
} else {
const firstReportID = _.first(reportIDs);
if (firstReportID) {
Onyx.set(ONYXKEYS.CURRENTLY_VIEWED_REPORTID, String(firstReportID));
}
return;
}

const firstReportID = _.first(reportIDs);
const currentReportID = firstReportID ? String(firstReportID) : '';
Onyx.merge(ONYXKEYS.CURRENTLY_VIEWED_REPORTID, currentReportID);
}

Log.info('[Report] Fetching report actions for reports', true, {reportIDs});
Expand Down

0 comments on commit 87c1540

Please sign in to comment.