From 8b79181dee03a7b8ea3abdf84c58d49213de6ecb Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 28 Jan 2025 22:25:25 +0300 Subject: [PATCH 01/13] add reportActionID in image markdown link --- src/ROUTES.ts | 6 ++++- src/components/AttachmentModal.tsx | 5 ++++ .../AttachmentCarousel/Pager/index.tsx | 2 +- .../AttachmentCarousel/extractAttachments.ts | 15 ------------ .../AttachmentCarousel/index.native.tsx | 10 ++++---- .../Attachments/AttachmentCarousel/index.tsx | 23 ++++++++++++------- .../Attachments/AttachmentCarousel/types.ts | 3 +++ .../HTMLRenderers/ImageRenderer.tsx | 2 +- .../HTMLRenderers/VideoRenderer.tsx | 2 +- src/libs/Navigation/types.ts | 1 + src/pages/home/report/ReportAttachments.tsx | 3 +++ 11 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 9972c03d7b686..595edc88d1c0b 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -343,6 +343,7 @@ const ROUTES = { route: 'attachment', getRoute: ( reportID: string | undefined, + reportActionID: string | undefined, type: ValueOf, url: string, accountID?: number, @@ -355,8 +356,11 @@ const ROUTES = { const authTokenParam = isAuthTokenRequired ? '&isAuthTokenRequired=true' : ''; const fileNameParam = fileName ? `&fileName=${fileName}` : ''; const attachmentLinkParam = attachmentLink ? `&attachmentLink=${attachmentLink}` : ''; + const reportActionParam = reportActionID ? `&reportActionID=${reportActionID}` : ''; - return `attachment?source=${encodeURIComponent(url)}&type=${type as string}${reportParam}${accountParam}${authTokenParam}${fileNameParam}${attachmentLinkParam}` as const; + return `attachment?source=${encodeURIComponent(url)}&type=${ + type as string + }${reportParam}${reportActionParam}${accountParam}${authTokenParam}${fileNameParam}${attachmentLinkParam}` as const; }, }, REPORT_PARTICIPANTS: { diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 74ff19f21a46f..1b5b11ba33c88 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -69,6 +69,9 @@ type AttachmentModalProps = { /** Optional source (URL, SVG function) for the image shown. If not passed in via props must be specified when modal is opened. */ source?: AvatarSource; + /** The report action id linked to the attachment. */ + reportActionID?: string; + /** Optional callback to fire when we want to preview an image and approve it for use. */ onConfirm?: ((file: FileObject) => void) | null; @@ -161,6 +164,7 @@ function AttachmentModal({ isLoading = false, shouldShowNotFoundPage = false, type = undefined, + reportActionID, accountID = undefined, shouldDisableSendButton = false, attachmentLink = '', @@ -552,6 +556,7 @@ function AttachmentModal({ )); diff --git a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts index 62660980f56f8..fae3c3ca1d2a9 100644 --- a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts +++ b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts @@ -27,10 +27,6 @@ function extractAttachments( const attachments: Attachment[] = []; const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report); - // We handle duplicate image sources by considering the first instance as original. Selecting any duplicate - // and navigating back (<) shows the image preceding the first instance, not the selected duplicate's position. - const uniqueSourcesAndLinks = new Set(); - let currentLink = ''; const htmlParser = new HtmlParser({ @@ -40,11 +36,7 @@ function extractAttachments( } if (name === 'video') { const source = tryResolveUrlFromApiRoot(attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]); - if (uniqueSourcesAndLinks.has(source)) { - return; - } - uniqueSourcesAndLinks.add(source); const fileName = attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE] || FileUtils.getFileName(`${source}`); attachments.unshift({ source: tryResolveUrlFromApiRoot(attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]), @@ -61,13 +53,6 @@ function extractAttachments( const expensifySource = attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE] ?? (new RegExp(CONST.ATTACHMENT_OR_RECEIPT_LOCAL_URL, 'i').test(attribs.src) ? attribs.src : null); const source = tryResolveUrlFromApiRoot(expensifySource || attribs.src); const previewSource = tryResolveUrlFromApiRoot(attribs.src); - const sourceLinkKey = `${source}|${currentLink}`; - - if (uniqueSourcesAndLinks.has(sourceLinkKey)) { - return; - } - - uniqueSourcesAndLinks.add(sourceLinkKey); let fileName = attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE] || FileUtils.getFileName(`${source}`); diff --git a/src/components/Attachments/AttachmentCarousel/index.native.tsx b/src/components/Attachments/AttachmentCarousel/index.native.tsx index 68668ccc6ab06..9f09915295335 100644 --- a/src/components/Attachments/AttachmentCarousel/index.native.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.native.tsx @@ -18,7 +18,7 @@ import AttachmentCarouselPager from './Pager'; import type {AttachmentCarouselProps} from './types'; import useCarouselArrows from './useCarouselArrows'; -function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibility, onClose, type, accountID}: AttachmentCarouselProps) { +function AttachmentCarousel({report, source, reportActionID, onNavigate, setDownloadButtonVisibility, onClose, type, accountID}: AttachmentCarouselProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const pagerRef = useRef(null); @@ -27,8 +27,8 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi const [page, setPage] = useState(); const [attachments, setAttachments] = useState([]); const {shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows} = useCarouselArrows(); - const [activeSource, setActiveSource] = useState(source); - const compareImage = useCallback((attachment: Attachment) => attachment.source === source, [source]); + const [activeAttachment, setActiveAttachmentID] = useState(reportActionID ?? source); + const compareImage = useCallback((attachment: Attachment) => (reportActionID ? attachment.reportActionID === reportActionID : attachment.source === source), [reportActionID, source]); useEffect(() => { const parentReportAction = report.parentReportActionID && parentReportActions ? parentReportActions[report.parentReportActionID] : undefined; @@ -80,7 +80,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi setPage(newPageIndex); if (newPageIndex >= 0 && item) { - setActiveSource(item.source); + setActiveAttachmentID(item.reportActionID ?? item.source); if (onNavigate) { onNavigate(item); } @@ -142,7 +142,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi updatePage(newPage)} onClose={onClose} diff --git a/src/components/Attachments/AttachmentCarousel/index.tsx b/src/components/Attachments/AttachmentCarousel/index.tsx index 50caaac3dd814..a5eeaa1fc4988 100644 --- a/src/components/Attachments/AttachmentCarousel/index.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.tsx @@ -51,7 +51,7 @@ function DeviceAwareGestureDetector({canUseTouchScreen, gesture, children}: Devi return canUseTouchScreen ? {children} : children; } -function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibility, type, accountID, onClose, attachmentLink}: AttachmentCarouselProps) { +function AttachmentCarousel({report, reportActionID, source, onNavigate, setDownloadButtonVisibility, type, accountID, onClose, attachmentLink}: AttachmentCarouselProps) { const theme = useTheme(); const {translate} = useLocalize(); const {windowWidth} = useWindowDimensions(); @@ -72,7 +72,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi ); const [page, setPage] = useState(0); const [attachments, setAttachments] = useState([]); - const [activeSource, setActiveSource] = useState(source); + const [activeAttachmentID, setActiveAttachmentID] = useState(reportActionID ?? source); const {shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows} = useCarouselArrows(); const {handleTap, handleScaleChange, isScrollEnabled} = useCarouselContextEvents(setShouldShowArrows); @@ -83,7 +83,11 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi setShouldShowArrows(true); }, [canUseTouchScreen, page, setShouldShowArrows]); - const compareImage = useCallback((attachment: Attachment) => attachment.source === source && (!attachmentLink || attachment.attachmentLink === attachmentLink), [attachmentLink, source]); + const compareImage = useCallback( + (attachment: Attachment) => + (reportActionID ? attachment.reportActionID === reportActionID : attachment.source === source) && (!attachmentLink || attachment.attachmentLink === attachmentLink), + [attachmentLink, reportActionID, source], + ); useEffect(() => { const parentReportAction = report.parentReportActionID && parentReportActions ? parentReportActions[report.parentReportActionID] : undefined; @@ -156,14 +160,14 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi // to get the index of the current page const entry = viewableItems.at(0); if (!entry) { - setActiveSource(null); + setActiveAttachmentID(null); return; } const item = entry.item as Attachment; if (entry.index !== null) { setPage(entry.index); - setActiveSource(item.source); + setActiveAttachmentID(item.reportActionID ?? item.source); } if (onNavigate) { @@ -193,7 +197,10 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi ); const extractItemKey = useCallback( - (item: Attachment) => (typeof item.source === 'string' || typeof item.source === 'number' ? `source-${item.source}|${item.attachmentLink}` : `reportActionID-${item.reportActionID}`), + (item: Attachment) => + !!item.reportActionID || (typeof item.source !== 'string' && typeof item.source !== 'number') + ? `reportActionID-${item.reportActionID}` + : `source-${item.source}|${item.attachmentLink}`, [], ); @@ -227,13 +234,13 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi ), - [activeSource, canUseTouchScreen, cellWidth, handleTap, shouldShowArrows, styles.h100], + [activeAttachmentID, canUseTouchScreen, cellWidth, handleTap, shouldShowArrows, styles.h100], ); /** Pan gesture handing swiping through attachments on touch screen devices */ const pan = useMemo( diff --git a/src/components/Attachments/AttachmentCarousel/types.ts b/src/components/Attachments/AttachmentCarousel/types.ts index 317878b3ff605..bbc599e2929d6 100644 --- a/src/components/Attachments/AttachmentCarousel/types.ts +++ b/src/components/Attachments/AttachmentCarousel/types.ts @@ -12,6 +12,9 @@ type AttachmentCarouselProps = { /** Source is used to determine the starting index in the array of attachments */ source: AttachmentSource; + /** The report action id linked to the current active attachment */ + reportActionID?: string; + /** Callback to update the parent modal's state with a source and name from the attachments array */ onNavigate?: (attachment: Attachment) => void; diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx index 4c8e941acb870..b72db964e50b8 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx @@ -110,7 +110,7 @@ function ImageRenderer({tnode}: ImageRendererProps) { } const attachmentLink = tnode.parent?.attributes?.href; - const route = ROUTES.ATTACHMENTS?.getRoute(reportID, type, source, accountID, isAttachmentOrReceipt, fileName, attachmentLink); + const route = ROUTES.ATTACHMENTS?.getRoute(reportID, action?.reportActionID, type, source, accountID, isAttachmentOrReceipt, fileName, attachmentLink); Navigation.navigate(route); }} onLongPress={(event) => { diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx index ad7ea87f4c9b2..0516b7c4049c8 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx @@ -46,7 +46,7 @@ function VideoRenderer({tnode, key}: VideoRendererProps) { if (!sourceURL || !type) { return; } - const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID ?? '-1', type, sourceURL, accountID); + const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID, undefined, type, sourceURL, accountID); Navigation.navigate(route); }} /> diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index efb2f3e9cb9a5..6b910c7cfb9f2 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1694,6 +1694,7 @@ type AuthScreensParamList = CentralPaneScreensParamList & [SCREENS.SUBMIT_EXPENSE]: undefined; [SCREENS.ATTACHMENTS]: { reportID: string; + reportActionID?: string; source: string; type: ValueOf; accountID: string; diff --git a/src/pages/home/report/ReportAttachments.tsx b/src/pages/home/report/ReportAttachments.tsx index dfac22b23f06a..a634ee7da8429 100644 --- a/src/pages/home/report/ReportAttachments.tsx +++ b/src/pages/home/report/ReportAttachments.tsx @@ -15,6 +15,7 @@ type ReportAttachmentsProps = PlatformStackScreenProps { const routeToNavigate = ROUTES.ATTACHMENTS.getRoute( reportID, + attachment.reportActionID, type, String(attachment.source), Number(accountID), @@ -49,6 +51,7 @@ function ReportAttachments({route}: ReportAttachmentsProps) { allowDownload defaultOpen report={report} + reportActionID={reportActionID} source={source} onModalClose={() => { Navigation.dismissModal(); From b901c9977b25d81cb69a7e200dbfc0899e225407 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 29 Jan 2025 01:01:36 +0300 Subject: [PATCH 02/13] fix lint --- .../AttachmentCarousel/extractAttachments.ts | 22 +++++++++--------- .../Attachments/AttachmentCarousel/index.tsx | 8 +++---- .../HTMLRenderers/ImageRenderer.tsx | 23 +++++++------------ .../HTMLRenderers/VideoRenderer.tsx | 6 ++--- src/components/VideoPlayerPreview/index.tsx | 2 +- src/pages/home/report/ReportAttachments.tsx | 2 +- 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts index fae3c3ca1d2a9..9e83b88f5b341 100644 --- a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts +++ b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts @@ -2,9 +2,9 @@ import {Parser as HtmlParser} from 'htmlparser2'; import type {OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {Attachment} from '@components/Attachments/types'; -import * as FileUtils from '@libs/fileDownload/FileUtils'; -import * as ReportActionsUtils from '@libs/ReportActionsUtils'; -import * as ReportUtils from '@libs/ReportUtils'; +import {getFileName, splitExtensionFromFileName} from '@libs/fileDownload/FileUtils'; +import {getReportActionHtml, getReportActionMessage, getSortedReportActions, isMoneyRequestAction, shouldReportActionBeVisible} from '@libs/ReportActionsUtils'; +import {canUserPerformWriteAction as canUserPerformWriteActionUtil} from '@libs/ReportUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; import CONST from '@src/CONST'; import type {Report, ReportAction, ReportActions} from '@src/types/onyx'; @@ -25,7 +25,7 @@ function extractAttachments( ) { const targetNote = privateNotes?.[Number(accountID)]?.note ?? ''; const attachments: Attachment[] = []; - const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report); + const canUserPerformWriteAction = canUserPerformWriteActionUtil(report); let currentLink = ''; @@ -37,7 +37,7 @@ function extractAttachments( if (name === 'video') { const source = tryResolveUrlFromApiRoot(attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]); - const fileName = attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE] || FileUtils.getFileName(`${source}`); + const fileName = attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE] || getFileName(`${source}`); attachments.unshift({ source: tryResolveUrlFromApiRoot(attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]), isAuthTokenRequired: !!attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE], @@ -54,7 +54,7 @@ function extractAttachments( const source = tryResolveUrlFromApiRoot(expensifySource || attribs.src); const previewSource = tryResolveUrlFromApiRoot(attribs.src); - let fileName = attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE] || FileUtils.getFileName(`${source}`); + let fileName = attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE] || getFileName(`${source}`); const width = (attribs['data-expensify-width'] && parseInt(attribs['data-expensify-width'], 10)) || undefined; const height = (attribs['data-expensify-height'] && parseInt(attribs['data-expensify-height'], 10)) || undefined; @@ -62,7 +62,7 @@ function extractAttachments( // Public image URLs might lack a file extension in the source URL, without an extension our // AttachmentView fails to recognize them as images and renders fallback content instead. // We apply this small hack to add an image extension and ensure AttachmentView renders the image. - const fileInfo = FileUtils.splitExtensionFromFileName(fileName); + const fileInfo = splitExtensionFromFileName(fileName); if (!fileInfo.fileExtension) { fileName = `${fileInfo.fileName || 'image'}.jpg`; } @@ -97,15 +97,15 @@ function extractAttachments( return attachments.reverse(); } - const actions = [...(parentReportAction ? [parentReportAction] : []), ...ReportActionsUtils.getSortedReportActions(Object.values(reportActions ?? {}))]; + const actions = [...(parentReportAction ? [parentReportAction] : []), ...getSortedReportActions(Object.values(reportActions ?? {}))]; actions.forEach((action, key) => { - if (!ReportActionsUtils.shouldReportActionBeVisible(action, key, canUserPerformWriteAction) || ReportActionsUtils.isMoneyRequestAction(action)) { + if (!shouldReportActionBeVisible(action, key, canUserPerformWriteAction) || isMoneyRequestAction(action)) { return; } - const decision = ReportActionsUtils.getReportActionMessage(action)?.moderationDecision?.decision; + const decision = getReportActionMessage(action)?.moderationDecision?.decision; const hasBeenFlagged = decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE || decision === CONST.MODERATION.MODERATOR_DECISION_HIDDEN; - const html = ReportActionsUtils.getReportActionHtml(action).replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`); + const html = getReportActionHtml(action).replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`); htmlParser.write(html); }); htmlParser.end(); diff --git a/src/components/Attachments/AttachmentCarousel/index.tsx b/src/components/Attachments/AttachmentCarousel/index.tsx index a5eeaa1fc4988..462384c1c324d 100644 --- a/src/components/Attachments/AttachmentCarousel/index.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.tsx @@ -9,14 +9,14 @@ import {useOnyx} from 'react-native-onyx'; import Animated, {scrollTo, useAnimatedRef, useSharedValue} from 'react-native-reanimated'; import type {Attachment, AttachmentSource} from '@components/Attachments/types'; import BlockingView from '@components/BlockingViews/BlockingView'; -import * as Illustrations from '@components/Icon/Illustrations'; +import {ToddBehindCloud} from '@components/Icon/Illustrations'; import {useFullScreenContext} from '@components/VideoPlayerContexts/FullScreenContext'; import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; -import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import {canUseTouchScreen as canUseTouchScreenUtil} from '@libs/DeviceCapabilities'; import Navigation from '@libs/Navigation/Navigation'; import variables from '@styles/variables'; import CONST from '@src/CONST'; @@ -63,7 +63,7 @@ function AttachmentCarousel({report, reportActionID, source, onNavigate, setDown const pagerRef = useRef(null); const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {canEvict: false}); const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false}); - const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen(); + const canUseTouchScreen = canUseTouchScreenUtil(); const modalStyles = styles.centeredModalStyles(shouldUseNarrowLayout, true); const cellWidth = useMemo( @@ -292,7 +292,7 @@ function AttachmentCarousel({report, reportActionID, source, onNavigate, setDown > {page === -1 ? ( Date: Mon, 3 Mar 2025 18:00:17 +0300 Subject: [PATCH 03/13] minor revert --- src/components/Attachments/AttachmentCarousel/Pager/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Attachments/AttachmentCarousel/Pager/index.tsx b/src/components/Attachments/AttachmentCarousel/Pager/index.tsx index eb681ba343d69..02d1475e69c59 100644 --- a/src/components/Attachments/AttachmentCarousel/Pager/index.tsx +++ b/src/components/Attachments/AttachmentCarousel/Pager/index.tsx @@ -130,6 +130,7 @@ function AttachmentCarouselPager( )); From 410351015a58fb59518a53582e0ce7f4b0e2db17 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 3 Mar 2025 18:25:12 +0300 Subject: [PATCH 04/13] update variable names --- .../Attachments/AttachmentCarousel/Pager/index.tsx | 8 ++++---- .../Attachments/AttachmentCarousel/index.native.tsx | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/Attachments/AttachmentCarousel/Pager/index.tsx b/src/components/Attachments/AttachmentCarousel/Pager/index.tsx index 02d1475e69c59..1be7685c84313 100644 --- a/src/components/Attachments/AttachmentCarousel/Pager/index.tsx +++ b/src/components/Attachments/AttachmentCarousel/Pager/index.tsx @@ -32,8 +32,8 @@ type AttachmentCarouselPagerProps = { /** The attachments to be rendered in the pager. */ items: Attachment[]; - /** The source (URL) of the currently active attachment. */ - activeSource: AttachmentSource; + /** The source (URL) or the linked report action id of the currently active attachment. */ + activeAttachmentID: AttachmentSource; /** The index of the initial page to be rendered. */ initialPage: number; @@ -58,7 +58,7 @@ type AttachmentCarouselPagerProps = { }; function AttachmentCarouselPager( - {items, activeSource, initialPage, setShouldShowArrows, onPageSelected, onClose, reportID}: AttachmentCarouselPagerProps, + {items, activeAttachmentID, initialPage, setShouldShowArrows, onPageSelected, onClose, reportID}: AttachmentCarouselPagerProps, ref: ForwardedRef, ) { const {handleTap, handleScaleChange, isScrollEnabled} = useCarouselContextEvents(setShouldShowArrows); @@ -129,7 +129,7 @@ function AttachmentCarouselPager( > diff --git a/src/components/Attachments/AttachmentCarousel/index.native.tsx b/src/components/Attachments/AttachmentCarousel/index.native.tsx index 63af3d84e5e7e..dab50786e0e34 100644 --- a/src/components/Attachments/AttachmentCarousel/index.native.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.native.tsx @@ -27,7 +27,7 @@ function AttachmentCarousel({report, source, reportActionID, onNavigate, setDown const [page, setPage] = useState(); const [attachments, setAttachments] = useState([]); const {shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows} = useCarouselArrows(); - const [activeAttachment, setActiveAttachmentID] = useState(reportActionID ?? source); + const [activeAttachmentID, setActiveAttachmentID] = useState(reportActionID ?? source); const compareImage = useCallback((attachment: Attachment) => (reportActionID ? attachment.reportActionID === reportActionID : attachment.source === source), [reportActionID, source]); useEffect(() => { @@ -142,7 +142,7 @@ function AttachmentCarousel({report, source, reportActionID, onNavigate, setDown updatePage(newPage)} onClose={onClose} From 4c2b419fcc836bd2a2e3ba78e588291bfb906262 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 10 Mar 2025 21:25:57 +0300 Subject: [PATCH 05/13] add report action id on video route --- .../Attachments/AttachmentCarousel/extractAttachments.ts | 5 ++++- .../HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts index 6208b841c762d..889748a024eb6 100644 --- a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts +++ b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts @@ -40,6 +40,7 @@ function extractAttachments( const fileName = attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE] || getFileName(`${source}`); attachments.unshift({ + reportActionID: attribs['data-id'], source: tryResolveUrlFromApiRoot(attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]), isAuthTokenRequired: !!attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE], file: {name: fileName}, @@ -113,7 +114,9 @@ function extractAttachments( const decision = getReportActionMessage(action)?.moderationDecision?.decision; const hasBeenFlagged = decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE || decision === CONST.MODERATION.MODERATOR_DECISION_HIDDEN; - const html = getReportActionHtml(action).replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`); + const html = getReportActionHtml(action) + .replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`) + .replace('