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 - Key Navigation - Pressing CTRL+K in attachment and closing search, leads to different chat #49750

Merged
merged 5 commits into from
Sep 27, 2024
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
2 changes: 2 additions & 0 deletions src/libs/actions/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ function closeTop() {
}
if (onModalClose) {
closeModals[closeModals.length - 1](isNavigate);
closeModals.pop();
return;
}
closeModals[closeModals.length - 1]();
closeModals.pop();
}

/**
Expand Down
32 changes: 8 additions & 24 deletions src/pages/TransactionReceiptPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList} from '@libs/Navigation/types';
Expand All @@ -13,19 +12,14 @@ import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot';
import * as ReportActions from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Report, ReportMetadata, Transaction} from '@src/types/onyx';

type TransactionReceiptOnyxProps = {
report: OnyxEntry<Report>;
transaction: OnyxEntry<Transaction>;
reportMetadata: OnyxEntry<ReportMetadata>;
};
type TransactionReceiptProps = StackScreenProps<AuthScreensParamList, typeof SCREENS.TRANSACTION_RECEIPT>;

type TransactionReceiptProps = TransactionReceiptOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.TRANSACTION_RECEIPT>;

function TransactionReceipt({transaction, report, reportMetadata = {isLoadingInitialReportActions: true}, route}: TransactionReceiptProps) {
function TransactionReceipt({route}: TransactionReceiptProps) {
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID ?? '-1'}`);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${route.params.transactionID ?? '-1'}`);
const [reportMetadata = {isLoadingInitialReportActions: true}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${route.params.reportID ?? '-1'}`);
const receiptURIs = ReceiptUtils.getThumbnailAndImageURIs(transaction);

const imageSource = tryResolveUrlFromApiRoot(receiptURIs.image ?? '');
Expand Down Expand Up @@ -65,7 +59,7 @@ function TransactionReceipt({transaction, report, reportMetadata = {isLoadingIni
originalFileName={receiptURIs?.filename}
defaultOpen
onModalClose={() => {
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(report?.reportID ?? '-1'));
Navigation.dismissModal(report?.reportID ?? '-1');
}}
Comment on lines 61 to 63
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, This caused this issue: #49887 and was fixed in this PR: #49915

isLoading={!transaction && reportMetadata?.isLoadingInitialReportActions}
shouldShowNotFoundPage={shouldShowNotFoundPage}
Expand All @@ -75,14 +69,4 @@ function TransactionReceipt({transaction, report, reportMetadata = {isLoadingIni

TransactionReceipt.displayName = 'TransactionReceipt';

export default withOnyx<TransactionReceiptProps, TransactionReceiptOnyxProps>({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID ?? '-1'}`,
},
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${route.params.transactionID ?? '-1'}`,
},
reportMetadata: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_METADATA}${route.params.reportID ?? '-1'}`,
},
})(TransactionReceipt);
export default TransactionReceipt;
15 changes: 2 additions & 13 deletions src/pages/home/report/ReportAttachments.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useEffect, useRef} from 'react';
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import type {Attachment} from '@components/Attachments/types';
Expand All @@ -19,14 +19,6 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
const accountID = route.params.accountID;
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const hasDismissedModalRef = useRef(false);

useEffect(
() => () => {
hasDismissedModalRef.current = false;
},
[],
);

// In native the imported images sources are of type number. Ref: https://reactnative.dev/docs/image#imagesource
const source = Number(route.params.source) || route.params.source;
Expand All @@ -48,10 +40,7 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
report={report}
source={source}
onModalClose={() => {
if (!hasDismissedModalRef.current) {
Navigation.dismissModal();
hasDismissedModalRef.current = true;
}
Navigation.dismissModal();
// This enables Composer refocus when the attachments modal is closed by the browser navigation
ComposerFocusManager.setReadyToFocus();
}}
Expand Down
Loading