Skip to content

Commit

Permalink
Merge pull request #50427 from shahinyan11/issues/50006
Browse files Browse the repository at this point in the history
  • Loading branch information
cead22 authored Oct 11, 2024
2 parents 2014ab8 + 3da847b commit 45a3a13
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ const ROUTES = {
},
ATTACHMENTS: {
route: 'attachment',
getRoute: (reportID: string, type: ValueOf<typeof CONST.ATTACHMENT_TYPE>, url: string, accountID?: number) =>
`attachment?source=${encodeURIComponent(url)}&type=${type}${reportID ? `&reportID=${reportID}` : ''}${accountID ? `&accountID=${accountID}` : ''}` as const,
getRoute: (reportID: string, type: ValueOf<typeof CONST.ATTACHMENT_TYPE>, url: string, accountID?: number, isAuthTokenRequired?: boolean) => {
const reportParam = reportID ? `&reportID=${reportID}` : '';
const accountParam = accountID ? `&accountID=${accountID}` : '';
const authTokenParam = isAuthTokenRequired ? '&isAuthTokenRequired=true' : '';
return `attachment?source=${encodeURIComponent(url)}&type=${type}${reportParam}${accountParam}${authTokenParam}` as const;
},
},
REPORT_PARTICIPANTS: {
route: 'r/:reportID/participants',
Expand Down
29 changes: 18 additions & 11 deletions src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {memo} from 'react';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import type {CustomRendererProps, TBlock} from 'react-native-render-html';
import {AttachmentContext} from '@components/AttachmentContext';
Expand Down Expand Up @@ -90,7 +90,7 @@ function ImageRenderer({tnode}: ImageRendererProps) {
return;
}

const route = ROUTES.ATTACHMENTS?.getRoute(reportID ?? '-1', type, source, accountID);
const route = ROUTES.ATTACHMENTS?.getRoute(reportID ?? '-1', type, source, accountID, isAttachmentOrReceipt);
Navigation.navigate(route);
}}
onLongPress={(event) => {
Expand All @@ -114,13 +114,20 @@ function ImageRenderer({tnode}: ImageRendererProps) {

ImageRenderer.displayName = 'ImageRenderer';

export default withOnyx<ImageRendererProps, ImageRendererWithOnyxProps>({
user: {
key: ONYXKEYS.USER,
},
})(
memo(
ImageRenderer,
(prevProps, nextProps) => prevProps.tnode.attributes === nextProps.tnode.attributes && prevProps.user?.shouldUseStagingServer === nextProps.user?.shouldUseStagingServer,
),
const ImageRendererMemorize = memo(
ImageRenderer,
(prevProps, nextProps) => prevProps.tnode.attributes === nextProps.tnode.attributes && prevProps.user?.shouldUseStagingServer === nextProps.user?.shouldUseStagingServer,
);

function ImageRendererWrapper(props: CustomRendererProps<TBlock>) {
const [user] = useOnyx(ONYXKEYS.USER);
return (
<ImageRendererMemorize
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
user={user}
/>
);
}

export default ImageRendererWrapper;
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ type AuthScreensParamList = CentralPaneScreensParamList &
source: string;
type: ValueOf<typeof CONST.ATTACHMENT_TYPE>;
accountID: string;
isAuthTokenRequired?: string;
};
[SCREENS.PROFILE_AVATAR]: {
accountID: string;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
const reportID = route.params.reportID;
const type = route.params.type;
const accountID = route.params.accountID;
const isAuthTokenRequired = route.params.isAuthTokenRequired;
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);

Expand Down Expand Up @@ -46,7 +47,7 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
}}
onCarouselAttachmentChange={onCarouselAttachmentChange}
shouldShowNotFoundPage={!isLoadingApp && type !== CONST.ATTACHMENT_TYPE.SEARCH && !report?.reportID}
isAuthTokenRequired={type === CONST.ATTACHMENT_TYPE.SEARCH}
isAuthTokenRequired={!!isAuthTokenRequired}
/>
);
}
Expand Down

0 comments on commit 45a3a13

Please sign in to comment.