Skip to content
Open
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,14 @@ const closeRHPFlow = (ref = navigationRef) => originalCloseRHPFlow(ref);
/**
* Close the side panel on narrow layout when navigating to a different screen.
*/
function closeSidePanelOnNarrowScreen() {
function closeSidePanelOnNarrowScreen(route: Route) {
const isExtraLargeScreenWidth = Dimensions.get('window').width > variables.sidePanelResponsiveWidthBreakpoint;
const isAttachmentPreviewRoute = route && /^r\/\d+\/attachment\/add/.test(route);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-2 (docs)

The hardcoded regex /^r\/\d+\/attachment\/add/ is a magic string that duplicates the route pattern already defined in ROUTES.REPORT_ADD_ATTACHMENT.route (r/:reportID/attachment/add). If that route definition ever changes, this regex will silently become stale.

Use the existing route constant instead. For example:

const isAttachmentPreviewRoute = new RegExp(`^${ROUTES.REPORT_ADD_ATTACHMENT.route.replace(":reportID", "\\d+")}`).test(route);

Or, since the route always starts with r/<digits>/attachment/add, you could use a simpler string-based check derived from the constant:

const attachmentRoutePrefix = ROUTES.REPORT_ADD_ATTACHMENT.route.split(":")[0]; // "r/"
const isAttachmentPreviewRoute = route.includes("/attachment/add") && route.startsWith(attachmentRoutePrefix);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented!


if (!sidePanelNVP?.openNarrowScreen || isExtraLargeScreenWidth) {
// If we have a side panel open on devices smaller than 1300px and the user wants to go to the REPORT_ADD_ATTACHMENT route,
// this means that the user clicked `Add Attachments` in the side panel, and in this case,
// there is no need to close the side panel, as we need to have access to the chat.
if (!sidePanelNVP?.openNarrowScreen || isExtraLargeScreenWidth || isAttachmentPreviewRoute) {
return;
}
SidePanelActions.closeSidePanel(true);
Expand Down Expand Up @@ -308,7 +312,7 @@ function navigate(route: Route, options?: LinkToOptions) {

const targetRoute = route.startsWith(CONST.SAML_REDIRECT_URL) ? ROUTES.HOME : route;
linkTo(navigationRef.current, targetRoute, options);
closeSidePanelOnNarrowScreen();
closeSidePanelOnNarrowScreen(route);
}
/**
* When routes are compared to determine whether the fallback route passed to the goUp function is in the state,
Expand Down
Loading