From bc742f20e19d85e68d02aa0713f2e1ef01dd66fc Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 20 Feb 2025 17:42:00 +0530 Subject: [PATCH] Use 3 --- web/apps/photos/src/components/Sidebar.tsx | 30 +++++++++++++--------- web/apps/photos/src/components/Upload.tsx | 7 ++++- web/apps/photos/src/pages/gallery.tsx | 4 +-- web/apps/photos/src/types/gallery/index.ts | 1 - 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsx index b5e2b7e936..cfe9e085eb 100644 --- a/web/apps/photos/src/components/Sidebar.tsx +++ b/web/apps/photos/src/components/Sidebar.tsx @@ -136,16 +136,21 @@ type SidebarProps = ModalVisibilityProps & { * items shown in the shortcut section within the sidebar. */ collectionSummaries: CollectionSummaries; + /** + * Called when the plan selection modal should be shown. + */ + onShowPlanSelector: () => void; }; export const Sidebar: React.FC = ({ open, onClose, collectionSummaries, + onShowPlanSelector, }) => ( - + = ({ onCloseSidebar }) => ( ); -interface UserDetailsSectionProps { +type UserDetailsSectionProps = Pick & { sidebarOpen: boolean; -} +}; const UserDetailsSection: React.FC = ({ sidebarOpen, + onShowPlanSelector, }) => { - const galleryContext = useContext(GalleryContext); const userDetails = useUserDetailsSnapshot(); const [memberSubscriptionManageView, setMemberSubscriptionManageView] = useState(false); @@ -223,7 +228,7 @@ const UserDetailsSection: React.FC = ({ ) { redirectToCustomerPortal(); } else { - galleryContext.showPlanSelectorModal(); + onShowPlanSelector(); } } }; @@ -244,7 +249,9 @@ const UserDetailsSection: React.FC = ({ onClick={handleSubscriptionCardClick} /> {userDetails && ( - + )} {isNonAdminFamilyMember && ( @@ -258,15 +265,14 @@ const UserDetailsSection: React.FC = ({ ); }; -interface SubscriptionStatusProps { +type SubscriptionStatusProps = Pick & { userDetails: UserDetails; -} +}; const SubscriptionStatus: React.FC = ({ userDetails, + onShowPlanSelector, }) => { - const { showPlanSelectorModal } = useContext(GalleryContext); - const hasAMessage = useMemo(() => { if (isPartOfFamily(userDetails) && !isFamilyAdmin(userDetails)) { return false; @@ -286,7 +292,7 @@ const SubscriptionStatus: React.FC = ({ if (isSubscriptionActive(userDetails.subscription)) { if (hasExceededStorageQuota(userDetails)) { - showPlanSelectorModal(); + onShowPlanSelector(); } } else { if ( @@ -295,7 +301,7 @@ const SubscriptionStatus: React.FC = ({ ) { redirectToCustomerPortal(); } else { - showPlanSelectorModal(); + onShowPlanSelector(); } } }; diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx index 1ec31eaf78..b266a9e8f0 100644 --- a/web/apps/photos/src/components/Upload.tsx +++ b/web/apps/photos/src/components/Upload.tsx @@ -101,6 +101,10 @@ interface UploadProps { * @param file The newly uploaded file. */ onUploadFile: (file: EnteFile) => void; + /** + * Called when the plan selection modal should be shown. + */ + onShowPlanSelector: () => void; setCollections?: (cs: Collection[]) => void; isFirstUpload?: boolean; uploadTypeSelectorView: boolean; @@ -120,6 +124,7 @@ export const Upload: React.FC = ({ isFirstUpload, dragAndDropFiles, onUploadFile, + onShowPlanSelector, showSessionExpiredMessage, ...props }) => { @@ -725,7 +730,7 @@ export const Upload: React.FC = ({ captionFirst: true, caption: t("storage_quota_exceeded"), title: t("upgrade_now"), - onClick: galleryContext.showPlanSelectorModal, + onClick: onShowPlanSelector, startIcon: , }); break; diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx index 7d82d4c04f..7b5010fcc3 100644 --- a/web/apps/photos/src/pages/gallery.tsx +++ b/web/apps/photos/src/pages/gallery.tsx @@ -133,7 +133,6 @@ import { import { FILE_OPS_TYPE, getSelectedFiles, handleFileOps } from "utils/file"; const defaultGalleryContext: GalleryContextType = { - showPlanSelectorModal: () => null, setActiveCollectionID: () => null, onShowCollection: () => null, syncWithRemote: () => null, @@ -812,7 +811,6 @@ const Page: React.FC = () => { dispatch({ @@ -983,6 +981,7 @@ const Page: React.FC = () => { onUploadFile={(file) => dispatch({ type: "uploadFile", file }) } + onShowPlanSelector={showPlanSelector} setCollections={(collections) => dispatch({ type: "setNormalCollections", collections }) } @@ -999,6 +998,7 @@ const Page: React.FC = () => { {!isInSearchMode && diff --git a/web/apps/photos/src/types/gallery/index.ts b/web/apps/photos/src/types/gallery/index.ts index dffe171cc3..2b619c5f30 100644 --- a/web/apps/photos/src/types/gallery/index.ts +++ b/web/apps/photos/src/types/gallery/index.ts @@ -39,7 +39,6 @@ export interface MergedSourceURL { } export interface GalleryContextType { - showPlanSelectorModal: () => void; setActiveCollectionID: (collectionID: number) => void; /** Newer and almost equivalent alternative to setActiveCollectionID. */ onShowCollection: (collectionID: number) => void;