2018-09-26 02:12:07 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2019-12-18 06:27:08 +01:00
|
|
|
import { withRouter } from 'react-router';
|
2021-06-01 05:04:26 +02:00
|
|
|
import LoadingBarOneOff from 'component/loadingBarOneOff';
|
2022-03-16 15:18:10 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
|
|
|
import { lazyImport } from 'util/lazyImport';
|
2021-06-11 08:06:29 +02:00
|
|
|
|
2022-03-16 15:18:10 +01:00
|
|
|
// prettier-ignore
|
|
|
|
const MAP = Object.freeze({
|
2022-05-18 11:13:14 +02:00
|
|
|
[MODALS.ANNOUNCEMENTS]: lazyImport(() => import('modal/modalAnnouncements' /* webpackChunkName: "modalAnnouncements" */)),
|
2022-03-16 15:18:10 +01:00
|
|
|
[MODALS.AFFIRM_PURCHASE]: lazyImport(() => import('modal/modalAffirmPurchase' /* webpackChunkName: "modalAffirmPurchase" */)),
|
|
|
|
[MODALS.AUTO_GENERATE_THUMBNAIL]: lazyImport(() => import('modal/modalAutoGenerateThumbnail' /* webpackChunkName: "modalAutoGenerateThumbnail" */)),
|
|
|
|
[MODALS.AUTO_UPDATE_DOWNLOADED]: lazyImport(() => import('modal/modalAutoUpdateDownloaded' /* webpackChunkName: "modalAutoUpdateDownloaded" */)),
|
|
|
|
[MODALS.BLOCK_CHANNEL]: lazyImport(() => import('modal/modalBlockChannel' /* webpackChunkName: "modalBlockChannel" */)),
|
|
|
|
[MODALS.COLLECTION_ADD]: lazyImport(() => import('modal/modalClaimCollectionAdd' /* webpackChunkName: "modalClaimCollectionAdd" */)),
|
|
|
|
[MODALS.COLLECTION_DELETE]: lazyImport(() => import('modal/modalRemoveCollection' /* webpackChunkName: "modalRemoveCollection" */)),
|
|
|
|
[MODALS.CONFIRM]: lazyImport(() => import('modal/modalConfirm' /* webpackChunkName: "modalConfirm" */)),
|
|
|
|
[MODALS.CONFIRM_AGE]: lazyImport(() => import('modal/modalConfirmAge' /* webpackChunkName: "modalConfirmAge" */)),
|
|
|
|
[MODALS.CONFIRM_CLAIM_REVOKE]: lazyImport(() => import('modal/modalRevokeClaim' /* webpackChunkName: "modalRevokeClaim" */)),
|
|
|
|
[MODALS.CONFIRM_EXTERNAL_RESOURCE]: lazyImport(() => import('modal/modalOpenExternalResource' /* webpackChunkName: "modalOpenExternalResource" */)),
|
|
|
|
[MODALS.CONFIRM_FILE_REMOVE]: lazyImport(() => import('modal/modalRemoveFile' /* webpackChunkName: "modalRemoveFile" */)),
|
|
|
|
[MODALS.CONFIRM_ODYSEE_MEMBERSHIP]: lazyImport(() => import('modal/modalConfirmOdyseeMembership' /* webpackChunkName: "modalConfirmOdyseeMembership" */)),
|
|
|
|
[MODALS.CONFIRM_REMOVE_CARD]: lazyImport(() => import('modal/modalRemoveCard' /* webpackChunkName: "modalRemoveCard" */)),
|
|
|
|
[MODALS.CONFIRM_REMOVE_COMMENT]: lazyImport(() => import('modal/modalRemoveComment' /* webpackChunkName: "modalRemoveComment" */)),
|
|
|
|
[MODALS.CONFIRM_THUMBNAIL_UPLOAD]: lazyImport(() => import('modal/modalConfirmThumbnailUpload' /* webpackChunkName: "modalConfirmThumbnailUpload" */)),
|
|
|
|
[MODALS.CONFIRM_TRANSACTION]: lazyImport(() => import('modal/modalConfirmTransaction' /* webpackChunkName: "modalConfirmTransaction" */)),
|
2022-03-22 14:44:44 +01:00
|
|
|
[MODALS.CUSTOMIZE_HOMEPAGE]: lazyImport(() => import('modal/modalCustomizeHomepage' /* webpackChunkName: "modalCustomizeHomepage" */)),
|
2022-03-16 15:18:10 +01:00
|
|
|
[MODALS.DOWNLOADING]: lazyImport(() => import('modal/modalDownloading' /* webpackChunkName: "modalDownloading" */)),
|
|
|
|
[MODALS.ERROR]: lazyImport(() => import('modal/modalError' /* webpackChunkName: "modalError" */)),
|
|
|
|
[MODALS.FILE_SELECTION]: lazyImport(() => import('modal/modalFileSelection' /* webpackChunkName: "modalFileSelection" */)),
|
|
|
|
[MODALS.FILE_TIMEOUT]: lazyImport(() => import('modal/modalFileTimeout' /* webpackChunkName: "modalFileTimeout" */)),
|
|
|
|
[MODALS.FIRST_REWARD]: lazyImport(() => import('modal/modalFirstReward' /* webpackChunkName: "modalFirstReward" */)),
|
2022-03-16 12:56:08 +01:00
|
|
|
[MODALS.HIDE_RECOMMENDATION]: lazyImport(() => import('modal/modalHideRecommendation' /* webpackChunkName: "modalHideRecommendation" */)),
|
2022-03-16 15:18:10 +01:00
|
|
|
[MODALS.IMAGE_UPLOAD]: lazyImport(() => import('modal/modalImageUpload' /* webpackChunkName: "modalImageUpload" */)),
|
|
|
|
[MODALS.LIQUIDATE_SUPPORTS]: lazyImport(() => import('modal/modalSupportsLiquidate' /* webpackChunkName: "modalSupportsLiquidate" */)),
|
|
|
|
[MODALS.MASS_TIP_UNLOCK]: lazyImport(() => import('modal/modalMassTipUnlock' /* webpackChunkName: "modalMassTipUnlock" */)),
|
|
|
|
[MODALS.MEMBERSHIP_SPLASH]: lazyImport(() => import('modal/modalMembershipSplash' /* webpackChunkName: "modalMembershipSplash" */)),
|
|
|
|
[MODALS.MIN_CHANNEL_AGE]: lazyImport(() => import('modal/modalMinChannelAge' /* webpackChunkName: "modalMinChannelAge" */)),
|
|
|
|
[MODALS.MOBILE_SEARCH]: lazyImport(() => import('modal/modalMobileSearch' /* webpackChunkName: "modalMobileSearch" */)),
|
|
|
|
[MODALS.PHONE_COLLECTION]: lazyImport(() => import('modal/modalPhoneCollection' /* webpackChunkName: "modalPhoneCollection" */)),
|
|
|
|
[MODALS.PUBLISH]: lazyImport(() => import('modal/modalPublish' /* webpackChunkName: "modalPublish" */)),
|
|
|
|
[MODALS.PUBLISH_PREVIEW]: lazyImport(() => import('modal/modalPublishPreview' /* webpackChunkName: "modalPublishPreview" */)),
|
2022-02-27 01:52:14 +01:00
|
|
|
[MODALS.REPOST]: lazyImport(() => import('modal/modalRepost' /* webpackChunkName: "modalRepost" */)),
|
2022-03-16 15:18:10 +01:00
|
|
|
[MODALS.REWARD_GENERATED_CODE]: lazyImport(() => import('modal/modalRewardCode' /* webpackChunkName: "modalRewardCode" */)),
|
|
|
|
[MODALS.SEND_TIP]: lazyImport(() => import('modal/modalSendTip' /* webpackChunkName: "modalSendTip" */)),
|
|
|
|
[MODALS.SET_REFERRER]: lazyImport(() => import('modal/modalSetReferrer' /* webpackChunkName: "modalSetReferrer" */)),
|
|
|
|
[MODALS.SOCIAL_SHARE]: lazyImport(() => import('modal/modalSocialShare' /* webpackChunkName: "modalSocialShare" */)),
|
|
|
|
[MODALS.SYNC_ENABLE]: lazyImport(() => import('modal/modalSyncEnable' /* webpackChunkName: "modalSyncEnable" */)),
|
|
|
|
[MODALS.TRANSACTION_FAILED]: lazyImport(() => import('modal/modalTransactionFailed' /* webpackChunkName: "modalTransactionFailed" */)),
|
|
|
|
[MODALS.UPGRADE]: lazyImport(() => import('modal/modalUpgrade' /* webpackChunkName: "modalUpgrade" */)),
|
|
|
|
[MODALS.VIEW_IMAGE]: lazyImport(() => import('modal/modalViewImage' /* webpackChunkName: "modalViewImage" */)),
|
|
|
|
[MODALS.WALLET_DECRYPT]: lazyImport(() => import('modal/modalWalletDecrypt' /* webpackChunkName: "modalWalletDecrypt" */)),
|
|
|
|
[MODALS.WALLET_ENCRYPT]: lazyImport(() => import('modal/modalWalletEncrypt' /* webpackChunkName: "modalWalletEncrypt" */)),
|
|
|
|
[MODALS.WALLET_PASSWORD_UNSAVE]: lazyImport(() => import('modal/modalPasswordUnsave' /* webpackChunkName: "modalPasswordUnsave" */)),
|
|
|
|
[MODALS.WALLET_UNLOCK]: lazyImport(() => import('modal/modalWalletUnlock' /* webpackChunkName: "modalWalletUnlock" */)),
|
|
|
|
[MODALS.YOUTUBE_WELCOME]: lazyImport(() => import('modal/modalYoutubeWelcome' /* webpackChunkName: "modalYoutubeWelcome" */)),
|
|
|
|
});
|
2021-11-03 03:06:57 +01:00
|
|
|
|
2018-04-02 18:03:12 +02:00
|
|
|
type Props = {
|
2019-01-08 03:46:33 +01:00
|
|
|
modal: { id: string, modalProps: {} },
|
2019-01-10 02:38:26 +01:00
|
|
|
error: { message: string },
|
2019-12-18 06:27:08 +01:00
|
|
|
location: { pathname: string },
|
|
|
|
hideModal: () => void,
|
2018-04-02 18:03:12 +02:00
|
|
|
};
|
|
|
|
|
2019-04-03 06:17:00 +02:00
|
|
|
function ModalRouter(props: Props) {
|
2019-12-18 06:27:08 +01:00
|
|
|
const { modal, error, location, hideModal } = props;
|
|
|
|
const { pathname } = location;
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
hideModal();
|
|
|
|
}, [pathname, hideModal]);
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2019-04-03 06:17:00 +02:00
|
|
|
if (error) {
|
2022-03-16 15:18:10 +01:00
|
|
|
const ModalError = MAP[MODALS.ERROR];
|
2021-11-03 03:06:57 +01:00
|
|
|
return (
|
|
|
|
<React.Suspense fallback={<LoadingBarOneOff />}>
|
|
|
|
<ModalError {...error} />
|
|
|
|
</React.Suspense>
|
|
|
|
);
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
2019-04-03 06:17:00 +02:00
|
|
|
if (!modal) {
|
|
|
|
return null;
|
2017-08-21 05:06:26 +02:00
|
|
|
}
|
|
|
|
|
2019-04-03 06:17:00 +02:00
|
|
|
const { id, modalProps } = modal;
|
2022-03-16 15:18:10 +01:00
|
|
|
const SelectedModal = MAP[id];
|
2019-04-03 06:17:00 +02:00
|
|
|
|
2022-03-16 15:18:10 +01:00
|
|
|
if (!SelectedModal) {
|
2021-06-11 08:06:29 +02:00
|
|
|
return null;
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
2021-06-11 08:06:29 +02:00
|
|
|
|
|
|
|
return (
|
2021-06-01 05:04:26 +02:00
|
|
|
<React.Suspense fallback={<LoadingBarOneOff />}>
|
2021-06-11 08:06:29 +02:00
|
|
|
<SelectedModal {...modalProps} />
|
|
|
|
</React.Suspense>
|
|
|
|
);
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
2019-12-18 06:27:08 +01:00
|
|
|
export default withRouter(ModalRouter);
|