π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(photos):restore-subscription-plan-skeleton
Aswin Asokda20b85b42e2
diff --git a/web/apps/photos/src/components/PlanSelector.tsx b/web/apps/photos/src/components/PlanSelector.tsxindex afa91ca328..0f2a9e39dd 100644--- a/web/apps/photos/src/components/PlanSelector.tsx+++ b/web/apps/photos/src/components/PlanSelector.tsx@@ -9,6 +9,7 @@ import {Dialog,IconButton,Link,+ Skeleton,Stack,styled,ToggleButton,@@ -61,7 +62,6 @@ import { Trans } from "react-i18next";type PlanSelectorProps = ModalVisibilityProps & {setLoading: (loading: boolean) => void;- initialPlansData?: PlansData;onManageFamily: () => void;};@@ -69,7 +69,6 @@ export const PlanSelector: React.FC<PlanSelectorProps> = ({open,onClose,setLoading,- initialPlansData,onManageFamily,}) => {const fullScreen = useMediaQuery(useTheme().breakpoints.down("sm"));@@ -84,12 +83,7 @@ export const PlanSelector: React.FC<PlanSelectorProps> = ({<SidebarDrawer {...{ open, onClose }} transitionDuration={0}><Box sx={{ maxWidth: 420, mx: "auto", py: 1 }}><PlanSelectorContents- {...{- onClose,- setLoading,- onManageFamily,- initialPlansData,- }}+ {...{ onClose, setLoading, onManageFamily }}/></Box></SidebarDrawer>@@ -111,7 +105,7 @@ export const PlanSelector: React.FC<PlanSelectorProps> = ({}}><PlanSelectorContents- {...{ onClose, setLoading, onManageFamily, initialPlansData }}+ {...{ onClose, setLoading, onManageFamily }}/></Dialog>);@@ -119,25 +113,21 @@ export const PlanSelector: React.FC<PlanSelectorProps> = ({export type PlanSelectorContentsProps = Pick<PlanSelectorProps,- "onClose" | "setLoading" | "onManageFamily" | "initialPlansData"-> & { onBeginCheckout?: () => void; showInitialLoading?: boolean };+ "onClose" | "setLoading" | "onManageFamily"+> & { onBeginCheckout?: () => void };export const PlanSelectorContents: React.FC<PlanSelectorContentsProps> = ({onClose,setLoading,- initialPlansData,onManageFamily,onBeginCheckout,- showInitialLoading = false,}) => {const { showMiniDialog } = useBaseContext();const showCloseButton = !useContext(SidebarPanelContext);const userDetails = useUserDetailsSnapshot();- const [plansData, setPlansData] = useState<PlansData | undefined>(- initialPlansData,- );+ const [plansData, setPlansData] = useState<PlansData | undefined>();const [planPeriod, setPlanPeriod] = useState<PlanPeriod>(userDetails?.subscription.period ?? "month",);@@ -155,11 +145,9 @@ export const PlanSelectorContents: React.FC<PlanSelectorContentsProps> = ({useEffect(() => {const request = { cancelled: false };- const showFetchLoading = showInitialLoading && !initialPlansData;- if (showFetchLoading) setLoading(true);void (async () => {try {- const plansData = initialPlansData ?? (await getPlansData());+ const plansData = await getPlansData();if (request.cancelled) return;const plans = [...plansData.plans];if (subscription && isSubscriptionActive(subscription)) {@@ -184,13 +172,10 @@ export const PlanSelectorContents: React.FC<PlanSelectorContentsProps> = ({log.error("Failed to get plans", e);onClose();showMiniDialog(genericRetriableErrorDialogAttributes());- } finally {- if (showFetchLoading && !request.cancelled) setLoading(false);}})();return () => {request.cancelled = true;- if (showFetchLoading) setLoading(false);};// eslint-disable-next-line react-hooks/exhaustive-deps}, []);@@ -531,7 +516,16 @@ const Plans: React.FC<PlansProps> = ({hasAddOnBonus,onPlanSelect,}) => (- <Stack sx={{ gap: 2 }}>+ <Stack sx={{ gap: 2 }} aria-busy={!plansData}>+ {!plansData &&+ [0, 1, 2].map((index) => (+ <Skeleton+ key={index}+ variant="rounded"+ height={64}+ animation="wave"+ />+ ))}{plansData?.plans.filter((plan) => plan.period === planPeriod).map((plan) => (diff --git a/web/apps/photos/src/components/sidebar/Sidebar.tsx b/web/apps/photos/src/components/sidebar/Sidebar.tsxindex 238b1c90d0..2845141fdb 100644--- a/web/apps/photos/src/components/sidebar/Sidebar.tsx+++ b/web/apps/photos/src/components/sidebar/Sidebar.tsx@@ -46,7 +46,6 @@ import {pullUserDetails,redirectToCustomerPortal,userDetailsAddOnBonuses,- type PlansData,type UserDetails,} from "ente-new/photos/services/user-details";import { usePhotosAppContext } from "ente-new/photos/types/context";@@ -76,7 +75,7 @@ type SidebarProps = ModalVisibilityProps & {onActionHandled?: (actionID: SidebarActionID) => void;onShowLargeFiles: () => void;onShowDuplicates: () => void;- onShowPlanSelector: (plansData?: PlansData) => void;+ onShowPlanSelector: () => void;collectionNameByID: Map<number, string>;onCloseOverlays: () => void;children?: (onRootClose: () => void) => React.ReactNode;@@ -593,7 +592,7 @@ const UserDetailsSection: React.FC<UserDetailsSectionProps> = ({);const handleSubscriptionCardClick = () =>- void openManageSubscription({+ openManageSubscription({userDetails,showManageMemberSubscription,onShowPlanSelector,diff --git a/web/apps/photos/src/components/sidebar/accounts/Account.tsx b/web/apps/photos/src/components/sidebar/accounts/Account.tsxindex f11bd6cbec..3f2831da44 100644--- a/web/apps/photos/src/components/sidebar/accounts/Account.tsx+++ b/web/apps/photos/src/components/sidebar/accounts/Account.tsx@@ -26,24 +26,16 @@ import type { SidebarActionID } from "ente-new/photos/services/search/types";import { disable2FA, get2FAStatus } from "ente-new/photos/services/user";import {familyMemberStorageLimit,- getPlansData,isFamilyAdmin,isPartOfFamily,isPartOfFamilyWithOtherMembers,isSubscriptionFree,pullUserDetails,userDetailsSnapshot,- type PlansData,} from "ente-new/photos/services/user-details";import { t } from "i18next";import { useRouter } from "next/router";-import React, {- useCallback,- useEffect,- useMemo,- useRef,- useState,-} from "react";+import React, { useCallback, useEffect, useMemo, useState } from "react";import { DeleteAccount } from "../account/DeleteAccount";import { SessionsSettings } from "../account/SessionsSettings";import { ManageMemberSubscription } from "./ManageMemberSubscription";@@ -64,7 +56,7 @@ export type AccountAction = Extract<type AccountProps = NestedSidebarDrawerVisibilityProps & {onAuthenticateUser: () => Promise<boolean>;- onShowPlanSelector: (plansData?: PlansData) => void;+ onShowPlanSelector: () => void;pendingAction?: AccountAction;onActionHandled?: (action?: AccountAction) => void;};@@ -78,20 +70,11 @@ export const Account: React.FC<AccountProps> = ({pendingAction,onActionHandled,}) => {- const { showMiniDialog, onGenericError } = useBaseContext();+ const { showMiniDialog } = useBaseContext();const userDetails = useUserDetailsSnapshot();const [twoFactorEnabled, setTwoFactorEnabled] = useState<boolean>();const [disablingTwoFactor, setDisablingTwoFactor] = useState(false);const [sessionCount, setSessionCount] = useState<number>();- const [subscriptionLoading, setSubscriptionLoading] = useState(false);- const subscriptionRequest = useRef(0);-- useEffect(() => {- if (!open) setSubscriptionLoading(false);- return () => {- subscriptionRequest.current += 1;- };- }, [open]);let planSubtext: string | undefined;if (userDetails) {@@ -174,40 +157,21 @@ export const Account: React.FC<AccountProps> = ({}, [router]);const handleManageSubscription = useCallback(() => {- if (subscriptionLoading) return;- const requestID = ++subscriptionRequest.current;- setSubscriptionLoading(true);void (async () => {- try {- if (!userDetails) await pullUserDetails();- if (subscriptionRequest.current != requestID) return;- const resolvedUserDetails =- userDetails ?? userDetailsSnapshot();- if (!resolvedUserDetails) return;- await openManageSubscription({- userDetails: resolvedUserDetails,- showManageMemberSubscription,- onShowPlanSelector: async () => {- const plansData = await getPlansData();- if (subscriptionRequest.current == requestID)- onShowPlanSelector(plansData);- },- });- } catch (error) {- if (subscriptionRequest.current == requestID)- onGenericError(error);- } finally {- if (subscriptionRequest.current == requestID)- setSubscriptionLoading(false);+ if (!userDetails) {+ await pullUserDetails();}++ const resolvedUserDetails = userDetails ?? userDetailsSnapshot();+ if (!resolvedUserDetails) return;++ openManageSubscription({+ userDetails: resolvedUserDetails,+ showManageMemberSubscription,+ onShowPlanSelector,+ });})();- }, [- subscriptionLoading,- userDetails,- showManageMemberSubscription,- onShowPlanSelector,- onGenericError,- ]);+ }, [onShowPlanSelector, showManageMemberSubscription, userDetails]);const handleRecoveryKey = useCallback(async () => {if (isDesktop) {@@ -362,7 +326,6 @@ export const Account: React.FC<AccountProps> = ({title={t("manage_plan")}subtitle={planSubtext}onClick={handleManageSubscription}- loading={subscriptionLoading}/><RowCardtitle={t("recovery_key")}diff --git a/web/apps/photos/src/components/sidebar/accounts/subscription.ts b/web/apps/photos/src/components/sidebar/accounts/subscription.tsindex a7d4475cda..9bf8b7606f 100644--- a/web/apps/photos/src/components/sidebar/accounts/subscription.ts+++ b/web/apps/photos/src/components/sidebar/accounts/subscription.ts@@ -14,7 +14,7 @@ export const openManageSubscription = ({}: {userDetails: UserDetails | undefined;showManageMemberSubscription: () => void;- onShowPlanSelector: () => void | Promise<void>;+ onShowPlanSelector: () => void;}) => {if (userDetails &&@@ -32,6 +32,6 @@ export const openManageSubscription = ({// eslint-disable-next-line @typescript-eslint/no-floating-promisesredirectToCustomerPortal();} else {- return onShowPlanSelector();+ onShowPlanSelector();}};diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex c8a0d9695e..0f13e6da2b 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -184,7 +184,6 @@ import {redirectToCustomerPortal,savedUserDetailsOrTriggerPull,verifyStripeSubscription,- type PlansData,} from "ente-new/photos/services/user-details";import { usePhotosAppContext } from "ente-new/photos/types/context";import { PromiseQueue } from "ente-utils/promise";@@ -305,16 +304,8 @@ const Page: React.FC = () => {const pendingPeopleSearchReset = useRef<(() => void) | undefined>(undefined,);- const { show: showPlanSelectorModal, props: planSelectorVisibilityProps } =+ const { show: showPlanSelector, props: planSelectorVisibilityProps } =useModalVisibility();- const [initialPlansData, setInitialPlansData] = useState<PlansData>();- const showPlanSelector = useCallback(- (plansData?: PlansData) => {- setInitialPlansData(plansData);- showPlanSelectorModal();- },- [showPlanSelectorModal],- );const {show: showFamilyManagement,props: familyManagementVisibilityProps,@@ -2130,7 +2121,6 @@ const Page: React.FC = () => {<><PlanSelector{...planSelectorVisibilityProps}- initialPlansData={initialPlansData}setLoading={(v) => setBlockingLoad(v)}onManageFamily={showFamilyManagement}/>diff --git a/web/apps/photos/src/pages/plan.tsx b/web/apps/photos/src/pages/plan.tsxindex 4d3f9fe01f..472aee6db8 100644--- a/web/apps/photos/src/pages/plan.tsx+++ b/web/apps/photos/src/pages/plan.tsx@@ -45,7 +45,6 @@ function PlanPage(): JSX.Element {<><PhotosAuthShell contentWidth={420}><PlanSelectorContents- showInitialLoadingonClose={handleContinue}setLoading={setIsLoading}onManageFamily={handleContinue}diff --git a/web/packages/base/components/v2/RowCard.tsx b/web/packages/base/components/v2/RowCard.tsxindex daa6001951..16b0be0ebc 100644--- a/web/packages/base/components/v2/RowCard.tsx+++ b/web/packages/base/components/v2/RowCard.tsx@@ -1,6 +1,5 @@import ChevronRightIcon from "@mui/icons-material/ChevronRight";import { Box, Stack, Typography } from "@mui/material";-import { ActivityIndicator } from "ente-base/components/mui/ActivityIndicator";import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";import React from "react";@@ -10,7 +9,6 @@ interface RowCardProps {subtitle?: string;onClick?: () => void;endIcon?: React.ReactNode;- loading?: boolean;}export const RowCard: React.FC<RowCardProps> = ({@@ -18,14 +16,11 @@ export const RowCard: React.FC<RowCardProps> = ({title,subtitle,onClick,- loading = false,endIcon = <ChevronRightIcon className="ente-chevron-right" />,}) => (<Boxcomponent={onClick ? FocusVisibleButton : "div"}onClick={onClick}- disabled={onClick ? loading : undefined}- aria-busy={loading || undefined}sx={[{display: "flex",@@ -77,6 +72,6 @@ export const RowCard: React.FC<RowCardProps> = ({</Typography>)}</Stack>- {loading ? <ActivityIndicator size={20} /> : endIcon}+ {endIcon}</Box>);