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 infinitely loading Of Attachment from qa.guide when opened in Search #50427

Merged
merged 11 commits into from
Oct 11, 2024
8 changes: 6 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,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 @@ -1456,6 +1456,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
Loading