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 /r/undefined issue #1790

Merged
merged 4 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
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
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