Skip to content

Commit 0c28b4e

Browse files
authored
Merge pull request #63630 from margelo/@chrispader/migrate-attachment-modals-to-modal-screens
Migrate `ReportAttachments` screen to `AttachmentModalScreen`
2 parents f875773 + 3b873aa commit 0c28b4e

File tree

20 files changed

+106
-257
lines changed

20 files changed

+106
-257
lines changed

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {CurrentReportIDContextProvider} from './hooks/useCurrentReportID';
4141
import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop';
4242
import HybridAppHandler from './HybridAppHandler';
4343
import OnyxUpdateManager from './libs/actions/OnyxUpdateManager';
44-
import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext';
44+
import {AttachmentModalContextProvider} from './pages/media/AttachmentModalScreen/AttachmentModalContext';
4545
import type {Route} from './ROUTES';
4646
import './setup/backgroundTask';
4747
import './setup/hybridApp';
@@ -95,7 +95,7 @@ function App({url, hybridAppSettings}: AppProps) {
9595
PopoverContextProvider,
9696
CurrentReportIDContextProvider,
9797
ScrollOffsetContextProvider,
98-
ReportAttachmentsProvider,
98+
AttachmentModalContextProvider,
9999
PickerStateProvider,
100100
EnvironmentProvider,
101101
CustomStatusBarAndBackgroundContextProvider,

src/ROUTES.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {IOUAction, IOUType} from './CONST';
55
import type {IOURequestType} from './libs/actions/IOU';
66
import Log from './libs/Log';
77
import type {ReimbursementAccountStepToOpen} from './libs/ReimbursementAccountUtils';
8+
import type {AttachmentModalScreenParams} from './pages/media/AttachmentModalScreen/types';
89
import SCREENS from './SCREENS';
910
import type {Screen} from './SCREENS';
1011
import type {ExitReason} from './types/form/ExitSurveyReasonForm';
@@ -442,28 +443,7 @@ const ROUTES = {
442443
},
443444
ATTACHMENTS: {
444445
route: 'attachment',
445-
getRoute: (
446-
reportID: string | undefined,
447-
attachmentID: string | undefined,
448-
type: ValueOf<typeof CONST.ATTACHMENT_TYPE> | undefined,
449-
url: string,
450-
accountID?: number,
451-
isAuthTokenRequired?: boolean,
452-
fileName?: string,
453-
attachmentLink?: string,
454-
hashKey?: number,
455-
) => {
456-
const typeParam = type ? `&type=${type}` : '';
457-
const reportParam = reportID ? `&reportID=${reportID}` : '';
458-
const accountParam = accountID ? `&accountID=${accountID}` : '';
459-
const authTokenParam = isAuthTokenRequired ? '&isAuthTokenRequired=true' : '';
460-
const fileNameParam = fileName ? `&fileName=${fileName}` : '';
461-
const attachmentLinkParam = attachmentLink ? `&attachmentLink=${attachmentLink}` : '';
462-
const attachmentIDParam = attachmentID ? `&attachmentID=${attachmentID}` : '';
463-
const hashKeyParam = hashKey ? `&hashKey=${hashKey}` : '';
464-
465-
return `attachment?source=${encodeURIComponent(url)}${typeParam}${reportParam}${attachmentIDParam}${accountParam}${authTokenParam}${fileNameParam}${attachmentLinkParam}${hashKeyParam}` as const;
466-
},
446+
getRoute: (params?: AttachmentRouteParams) => getAttachmentModalScreenRoute('attachment', params),
467447
},
468448
REPORT_PARTICIPANTS: {
469449
route: 'r/:reportID/participants',
@@ -483,7 +463,7 @@ const ROUTES = {
483463
},
484464
REPORT_WITH_ID_DETAILS: {
485465
route: 'r/:reportID/details',
486-
getRoute: (reportID: string | undefined, backTo?: string) => {
466+
getRoute: (reportID: string | number | undefined, backTo?: string) => {
487467
if (!reportID) {
488468
Log.warn('Invalid reportID is used to build the REPORT_WITH_ID_DETAILS route');
489469
}
@@ -2633,6 +2613,30 @@ const SHARED_ROUTE_PARAMS: Partial<Record<Screen, string[]>> = {
26332613
export {HYBRID_APP_ROUTES, getUrlWithBackToParam, PUBLIC_SCREENS_ROUTES, SHARED_ROUTE_PARAMS};
26342614
export default ROUTES;
26352615

2616+
type AttachmentsRoute = typeof ROUTES.ATTACHMENTS.route;
2617+
type ReportAddAttachmentRoute = `r/${string}/attachment/add`;
2618+
type AttachmentRoutes = AttachmentsRoute | ReportAddAttachmentRoute;
2619+
type AttachmentRouteParams = AttachmentModalScreenParams;
2620+
2621+
function getAttachmentModalScreenRoute(url: AttachmentRoutes, params?: AttachmentRouteParams) {
2622+
if (!params?.source) {
2623+
return url;
2624+
}
2625+
2626+
const {source, attachmentID, type, reportID, accountID, isAuthTokenRequired, originalFileName, attachmentLink} = params;
2627+
2628+
const sourceParam = `?source=${encodeURIComponent(source as string)}`;
2629+
const attachmentIDParam = attachmentID ? `&attachmentID=${attachmentID}` : '';
2630+
const typeParam = type ? `&type=${type as string}` : '';
2631+
const reportIDParam = reportID ? `&reportID=${reportID}` : '';
2632+
const accountIDParam = accountID ? `&accountID=${accountID}` : '';
2633+
const authTokenParam = isAuthTokenRequired ? '&isAuthTokenRequired=true' : '';
2634+
const fileNameParam = originalFileName ? `&originalFileName=${originalFileName}` : '';
2635+
const attachmentLinkParam = attachmentLink ? `&attachmentLink=${attachmentLink}` : '';
2636+
2637+
return `${url}${sourceParam}${typeParam}${reportIDParam}${attachmentIDParam}${accountIDParam}${authTokenParam}${fileNameParam}${attachmentLinkParam} ` as const;
2638+
}
2639+
26362640
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26372641
type ExtractRouteName<TRoute> = TRoute extends {getRoute: (...args: any[]) => infer TRouteName} ? TRouteName : TRoute;
26382642

src/components/Attachments/AttachmentCarousel/CarouselItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SafeAreaConsumer from '@components/SafeAreaConsumer';
1010
import Text from '@components/Text';
1111
import useLocalize from '@hooks/useLocalize';
1212
import useThemeStyles from '@hooks/useThemeStyles';
13-
import ReportAttachmentsContext from '@pages/home/report/ReportAttachmentsContext';
13+
import AttachmentModalContext from '@pages/media/AttachmentModalScreen/AttachmentModalContext';
1414
import CONST from '@src/CONST';
1515

1616
type CarouselItemProps = {
@@ -33,7 +33,7 @@ type CarouselItemProps = {
3333
function CarouselItem({item, onPress, isFocused, isModalHovered, reportID}: CarouselItemProps) {
3434
const styles = useThemeStyles();
3535
const {translate} = useLocalize();
36-
const {isAttachmentHidden} = useContext(ReportAttachmentsContext);
36+
const {isAttachmentHidden} = useContext(AttachmentModalContext);
3737
const [isHidden, setIsHidden] = useState(() => (item.reportActionID && isAttachmentHidden(item.reportActionID)) ?? item.hasBeenFlagged);
3838

3939
const renderButton = (style: StyleProp<ViewStyle>) => (

src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ function ImageRenderer({tnode}: ImageRendererProps) {
112112
}
113113

114114
const attachmentLink = tnode.parent?.attributes?.href;
115-
const route = ROUTES.ATTACHMENTS?.getRoute(reportID, attachmentID, type, source, accountID, isAttachmentOrReceipt, fileName, attachmentLink);
115+
const route = ROUTES.ATTACHMENTS?.getRoute({
116+
attachmentID,
117+
reportID,
118+
type,
119+
source,
120+
accountID,
121+
isAuthTokenRequired: isAttachmentOrReceipt,
122+
originalFileName: fileName,
123+
attachmentLink,
124+
});
116125
Navigation.navigate(route);
117126
}}
118127
onLongPress={(event) => {

src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function VideoRenderer({tnode, key}: VideoRendererProps) {
4646
return;
4747
}
4848
const isAuthTokenRequired = !!htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE];
49-
const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID, attachmentID, type, sourceURL, accountID, isAuthTokenRequired, undefined, undefined, hashKey);
49+
const route = ROUTES.ATTACHMENTS.getRoute({attachmentID, reportID: report?.reportID, type, source: sourceURL, accountID, isAuthTokenRequired, hashKey});
5050
Navigation.navigate(route);
5151
}}
5252
/>

src/libs/Navigation/AppNavigator/AuthScreens.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import type * as OnyxTypes from '@src/types/onyx';
6262
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
6363
import {isEmptyObject} from '@src/types/utils/EmptyObject';
6464
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
65+
import attachmentModalScreenOptions from './attachmentModalScreenOptions';
6566
import createRootStackNavigator from './createRootStackNavigator';
6667
import {screensWithEnteringAnimation, workspaceSplitsWithoutEnteringAnimation} from './createRootStackNavigator/GetStateForActionHandlers';
6768
import defaultScreenOptions from './defaultScreenOptions';
@@ -88,7 +89,7 @@ type AuthScreensProps = {
8889
initialLastUpdateIDAppliedToClient: OnyxEntry<number>;
8990
};
9091

91-
const loadReportAttachments = () => require<ReactComponentModule>('../../../pages/home/report/ReportAttachments').default;
92+
const loadAttachmentModalScreen = () => require<ReactComponentModule>('../../../pages/media/AttachmentModalScreen').default;
9293
const loadValidateLoginPage = () => require<ReactComponentModule>('../../../pages/ValidateLoginPage').default;
9394
const loadLogOutPreviousUserPage = () => require<ReactComponentModule>('../../../pages/LogOutPreviousUserPage').default;
9495
const loadConciergePage = () => require<ReactComponentModule>('../../../pages/ConciergePage').default;
@@ -184,11 +185,11 @@ function handleNetworkReconnect() {
184185
}
185186

186187
const RootStack = createRootStackNavigator<AuthScreensParamList>();
188+
187189
// We want to delay the re-rendering for components(e.g. ReportActionCompose)
188190
// that depends on modal visibility until Modal is completely closed and its focused
189191
// When modal screen is focused, update modal visibility in Onyx
190192
// https://reactnavigation.org/docs/navigation-events/
191-
192193
const modalScreenListeners = {
193194
focus: () => {
194195
Modal.setModalVisibility(true, CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED);
@@ -600,11 +601,8 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
600601
/>
601602
<RootStack.Screen
602603
name={SCREENS.ATTACHMENTS}
603-
options={{
604-
headerShown: false,
605-
presentation: Presentation.TRANSPARENT_MODAL,
606-
}}
607-
getComponent={loadReportAttachments}
604+
options={attachmentModalScreenOptions}
605+
getComponent={loadAttachmentModalScreen}
608606
listeners={modalScreenListeners}
609607
/>
610608
<RootStack.Screen

src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
1515

1616
const loadReportScreen = () => require<ReactComponentModule>('@pages/home/ReportScreen').default;
1717
const loadSidebarScreen = () => require<ReactComponentModule>('@pages/home/sidebar/BaseSidebarScreen').default;
18-
1918
const Split = createSplitNavigator<ReportsSplitNavigatorParamList>();
2019

2120
/**

src/libs/Navigation/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,7 @@ type ReportsSplitNavigatorParamList = {
17621762
moneyRequestReportActionID?: string;
17631763
transactionID?: string;
17641764
};
1765+
[SCREENS.ATTACHMENTS]: AttachmentModalScreenParams;
17651766
};
17661767

17671768
type SettingsSplitNavigatorParamList = {
@@ -1969,6 +1970,7 @@ type SharedScreensParamList = {
19691970
shortLivedAuthToken?: string;
19701971
shortLivedToken?: string;
19711972
authTokenType?: ValueOf<typeof CONST.AUTH_TOKEN_TYPES>;
1973+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
19721974
exitTo?: Routes | HybridAppRoute;
19731975
shouldForceLogin: string;
19741976
domain?: Routes;
@@ -1977,6 +1979,7 @@ type SharedScreensParamList = {
19771979
[SCREENS.VALIDATE_LOGIN]: {
19781980
accountID: string;
19791981
validateCode: string;
1982+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
19801983
exitTo?: Routes | HybridAppRoute;
19811984
};
19821985
};

src/pages/home/report/PureReportActionItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ import {
152152
import SelectionScraper from '@libs/SelectionScraper';
153153
import shouldRenderAddPaymentCard from '@libs/shouldRenderAppPaymentCard';
154154
import {ReactionListContext} from '@pages/home/ReportScreenContext';
155+
import AttachmentModalContext from '@pages/media/AttachmentModalScreen/AttachmentModalContext';
155156
import variables from '@styles/variables';
156157
import {openPersonalBankAccountSetupView} from '@userActions/BankAccounts';
157158
import {hideEmojiPicker, isActive} from '@userActions/EmojiPickerAction';
@@ -181,7 +182,6 @@ import ReportActionItemMessage from './ReportActionItemMessage';
181182
import ReportActionItemMessageEdit from './ReportActionItemMessageEdit';
182183
import ReportActionItemSingle from './ReportActionItemSingle';
183184
import ReportActionItemThread from './ReportActionItemThread';
184-
import ReportAttachmentsContext from './ReportAttachmentsContext';
185185
import TripSummary from './TripSummary';
186186

187187
type PureReportActionItemProps = {
@@ -438,7 +438,7 @@ function PureReportActionItem({
438438
const [isHidden, setIsHidden] = useState(false);
439439
const [moderationDecision, setModerationDecision] = useState<OnyxTypes.DecisionName>(CONST.MODERATION.MODERATOR_DECISION_APPROVED);
440440
const reactionListRef = useContext(ReactionListContext);
441-
const {updateHiddenAttachments} = useContext(ReportAttachmentsContext);
441+
const {updateHiddenAttachments} = useContext(AttachmentModalContext);
442442
const composerTextInputRef = useRef<TextInput | HTMLTextAreaElement>(null);
443443
const popoverAnchorRef = useRef<Exclude<ContextMenuAnchor, TextInput>>(null);
444444
const downloadedPreviews = useRef<string[]>([]);

src/pages/home/report/ReportAttachments.tsx

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)