Skip to content

Commit 9ec1076

Browse files
committed
Revert CachedPDFPaths refactor
1 parent 4fa3ea3 commit 9ec1076

8 files changed

Lines changed: 38 additions & 186 deletions

File tree

src/components/Attachments/AttachmentView/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ function AttachmentView({
123123
reportID,
124124
}: AttachmentViewProps) {
125125
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`, {canBeMissing: true});
126-
const [pdfsPaths] = useOnyx(ONYXKEYS.CACHED_PDF_PATHS, {canBeMissing: true});
127126
const {translate} = useLocalize();
128127
const {updateCurrentURLAndReportID} = usePlaybackContext();
129128

@@ -213,7 +212,7 @@ function AttachmentView({
213212
const onPDFLoadComplete = (path: string) => {
214213
const id = (transaction && transaction.transactionID) ?? reportActionID;
215214
if (path && id) {
216-
addCachedPDFPaths(id, path, pdfsPaths ?? {});
215+
addCachedPDFPaths(id, path);
217216
}
218217
if (!loadComplete) {
219218
setLoadComplete(true);

src/libs/actions/CachedPDFPaths/index.native.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ import type {Add, Clear, ClearByKey} from './types';
77
* We need to save the paths of PDF files so we can delete them later.
88
* This is to remove the cached PDFs when an attachment is deleted or the user logs out.
99
*/
10-
const add: Add = (id: string, path: string, pdfPaths: Record<string, string>) => {
10+
let pdfPaths: Record<string, string> = {};
11+
Onyx.connect({
12+
key: ONYXKEYS.CACHED_PDF_PATHS,
13+
callback: (val) => {
14+
pdfPaths = val ?? {};
15+
},
16+
});
17+
18+
const add: Add = (id: string, path: string) => {
1119
if (pdfPaths[id]) {
1220
return Promise.resolve();
1321
}
@@ -28,7 +36,7 @@ const clear: Clear = (path: string) => {
2836
});
2937
};
3038

31-
const clearByKey: ClearByKey = (id: string, pdfPaths: Record<string, string>) => {
39+
const clearByKey: ClearByKey = (id: string) => {
3240
clear(pdfPaths[id] ?? '').then(() => Onyx.merge(ONYXKEYS.CACHED_PDF_PATHS, {[id]: null}));
3341
};
3442

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
type Add = (id: string, path: string, pdfPaths: Record<string, string>) => Promise<void | void[]>;
1+
type Add = (id: string, path: string) => Promise<void | void[]>;
22
type Clear = (path: string) => Promise<void>;
3-
type ClearByKey = (id: string, pdfPaths: Record<string, string>) => void;
3+
type ClearByKey = (id: string) => void;
44

55
export type {Add, Clear, ClearByKey};

src/libs/actions/IOU.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8019,7 +8019,6 @@ function deleteMoneyRequest(
80198019
violations: OnyxCollection<OnyxTypes.TransactionViolations>,
80208020
isSingleTransactionView = false,
80218021
transactionIDsPendingDeletion?: string[],
8022-
pdfsPaths?: Record<string, string>,
80238022
) {
80248023
if (!transactionID) {
80258024
return;
@@ -8304,7 +8303,7 @@ function deleteMoneyRequest(
83048303

83058304
// STEP 3: Make the API request
83068305
API.write(WRITE_COMMANDS.DELETE_MONEY_REQUEST, parameters, {optimisticData, successData, failureData});
8307-
clearPdfByOnyxKey(transactionID, pdfsPaths ?? {});
8306+
clearPdfByOnyxKey(transactionID);
83088307

83098308
return urlToNavigateBack;
83108309
}
@@ -8316,7 +8315,6 @@ function deleteTrackExpense(
83168315
transactions: OnyxCollection<OnyxTypes.Transaction>,
83178316
violations: OnyxCollection<OnyxTypes.TransactionViolations>,
83188317
isSingleTransactionView = false,
8319-
pdfsPaths?: Record<string, string>,
83208318
) {
83218319
if (!chatReportID || !transactionID) {
83228320
return;
@@ -8327,7 +8325,7 @@ function deleteTrackExpense(
83278325
// STEP 1: Get all collections we're updating
83288326
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`] ?? null;
83298327
if (!isSelfDM(chatReport)) {
8330-
deleteMoneyRequest(transactionID, reportAction, transactions, violations, isSingleTransactionView, undefined, pdfsPaths);
8328+
deleteMoneyRequest(transactionID, reportAction, transactions, violations, isSingleTransactionView);
83318329
return urlToNavigateBack;
83328330
}
83338331

@@ -8346,7 +8344,7 @@ function deleteTrackExpense(
83468344

83478345
// STEP 6: Make the API request
83488346
API.write(WRITE_COMMANDS.DELETE_MONEY_REQUEST, parameters, {optimisticData, successData, failureData});
8349-
clearPdfByOnyxKey(transactionID, pdfsPaths ?? {});
8347+
clearPdfByOnyxKey(transactionID);
83508348

83518349
// STEP 7: Navigate the user depending on which page they are on and which resources were deleted
83528350
return urlToNavigateBack;

src/libs/actions/Report.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ function handleReportChanged(report: OnyxEntry<Report>) {
18481848
}
18491849

18501850
/** Deletes a comment from the report, basically sets it as empty string */
1851-
function deleteReportComment(reportID: string | undefined, reportAction: ReportAction, pdfsPaths: Record<string, string>) {
1851+
function deleteReportComment(reportID: string | undefined, reportAction: ReportAction) {
18521852
const originalReportID = getOriginalReportID(reportID, reportAction);
18531853
const reportActionID = reportAction.reportActionID;
18541854

@@ -1970,7 +1970,7 @@ function deleteReportComment(reportID: string | undefined, reportAction: ReportA
19701970
reportActionID,
19711971
};
19721972

1973-
clearByKey(reportActionID, pdfsPaths);
1973+
clearByKey(reportActionID);
19741974

19751975
API.write(
19761976
WRITE_COMMANDS.DELETE_COMMENT,
@@ -2036,13 +2036,7 @@ function handleUserDeletedLinksInHtml(newCommentText: string, originalCommentMar
20362036
}
20372037

20382038
/** Saves a new message for a comment. Marks the comment as edited, which will be reflected in the UI. */
2039-
function editReportComment(
2040-
reportID: string | undefined,
2041-
originalReportAction: OnyxEntry<ReportAction>,
2042-
textForNewComment: string,
2043-
videoAttributeCache?: Record<string, string>,
2044-
pdfsPaths?: Record<string, string>,
2045-
) {
2039+
function editReportComment(reportID: string | undefined, originalReportAction: OnyxEntry<ReportAction>, textForNewComment: string, videoAttributeCache?: Record<string, string>) {
20462040
const originalReportID = getOriginalReportID(reportID, originalReportAction);
20472041
if (!originalReportID || !originalReportAction) {
20482042
return;
@@ -2074,7 +2068,7 @@ function editReportComment(
20742068

20752069
// Delete the comment if it's empty
20762070
if (!htmlForNewComment) {
2077-
deleteReportComment(originalReportID, originalReportAction, pdfsPaths ?? {});
2071+
deleteReportComment(originalReportID, originalReportAction);
20782072
return;
20792073
}
20802074

src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import React, {forwardRef, useCallback, useContext, useEffect, useImperativeHand
66
import type {EmitterSubscription, GestureResponderEvent, NativeTouchEvent, View} from 'react-native';
77
import {DeviceEventEmitter, Dimensions, InteractionManager} from 'react-native';
88
import type {OnyxEntry} from 'react-native-onyx';
9-
import {useOnyx} from 'react-native-onyx';
109
import {Actions, ActionSheetAwareScrollViewContext} from '@components/ActionSheetAwareScrollView';
1110
import ConfirmModal from '@components/ConfirmModal';
1211
import PopoverWithMeasuredContent from '@components/PopoverWithMeasuredContent';
@@ -17,7 +16,6 @@ import {deleteReportComment} from '@libs/actions/Report';
1716
import calculateAnchorPosition from '@libs/calculateAnchorPosition';
1817
import {getOriginalMessage, isMoneyRequestAction, isTrackExpenseAction} from '@libs/ReportActionsUtils';
1918
import CONST from '@src/CONST';
20-
import ONYXKEYS from '@src/ONYXKEYS';
2119
import type {AnchorDimensions} from '@src/styles';
2220
import type {ReportAction} from '@src/types/onyx';
2321
import BaseReportActionContextMenu from './BaseReportActionContextMenu';
@@ -38,7 +36,6 @@ function extractPointerEvent(event: GestureResponderEvent | MouseEvent): MouseEv
3836

3937
function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<ReportActionContextMenu>) {
4038
const {translate} = useLocalize();
41-
const [pdfsPaths] = useOnyx(ONYXKEYS.CACHED_PDF_PATHS, {canBeMissing: true});
4239
const reportIDRef = useRef<string | undefined>(undefined);
4340
const typeRef = useRef<ContextMenuType | undefined>(undefined);
4441
const reportActionRef = useRef<NonNullable<OnyxEntry<ReportAction>> | null>(null);
@@ -298,19 +295,19 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
298295
if (isMoneyRequestAction(reportAction)) {
299296
const originalMessage = getOriginalMessage(reportAction);
300297
if (isTrackExpenseAction(reportAction)) {
301-
deleteTrackExpense(reportIDRef.current, originalMessage?.IOUTransactionID, reportAction, duplicateTransactions, duplicateTransactionViolations, false, pdfsPaths ?? {});
298+
deleteTrackExpense(reportIDRef.current, originalMessage?.IOUTransactionID, reportAction, duplicateTransactions, duplicateTransactionViolations);
302299
} else {
303-
deleteMoneyRequest(originalMessage?.IOUTransactionID, reportAction, duplicateTransactions, duplicateTransactionViolations, false, undefined, pdfsPaths ?? {});
300+
deleteMoneyRequest(originalMessage?.IOUTransactionID, reportAction, duplicateTransactions, duplicateTransactionViolations);
304301
}
305302
} else if (reportAction) {
306303
InteractionManager.runAfterInteractions(() => {
307-
deleteReportComment(reportIDRef.current, reportAction, pdfsPaths ?? {});
304+
deleteReportComment(reportIDRef.current, reportAction);
308305
});
309306
}
310307

311308
DeviceEventEmitter.emit(`deletedReportAction_${reportIDRef.current}`, reportAction?.reportActionID);
312309
setIsDeleteCommentConfirmModalVisible(false);
313-
}, [pdfsPaths, duplicateTransactions, duplicateTransactionViolations]);
310+
}, [duplicateTransactions, duplicateTransactionViolations]);
314311

315312
const hideDeleteModal = () => {
316313
callbackWhenDeleteModalHide.current = () => (onCancelDeleteModal.current = runAndResetCallback(onCancelDeleteModal.current));

0 commit comments

Comments
 (0)