π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
wip checkpoint
Manav Rathi13e013eaa923
diff --git a/web/apps/photos/src/components/MemberSubscriptionManage.tsx b/web/apps/photos/src/components/MemberSubscriptionManage.tsxindex 6d90b99652..d7f2419ffe 100644--- a/web/apps/photos/src/components/MemberSubscriptionManage.tsx+++ b/web/apps/photos/src/components/MemberSubscriptionManage.tsx@@ -58,7 +58,7 @@ export function MemberSubscriptionManage({ open, userDetails, onClose }) {{t("subscription_info_family")}</Typography><Typography>- {getFamilyPlanAdmin(userDetails.familyData)?.email}+ {getFamilyPlanAdmin(userDetails)?.email}</Typography></Box>diff --git a/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx b/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsxindex 9287c1cb39..d812e839dd 100644--- a/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx+++ b/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx@@ -1,10 +1,10 @@import { Overlay } from "@/base/components/mui/Container";import type { ButtonishProps } from "@/new/photos/components/mui";-import type { UserDetails } from "@/new/photos/services/user";import {- hasNonAdminFamilyMembers,isPartOfFamily,+ isPartOfFamilyWithOtherMembers,} from "@/new/photos/services/family";+import type { UserDetails } from "@/new/photos/services/user";import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";import { SpaceBetweenFlex } from "@ente/shared/components/Container";import ChevronRightIcon from "@mui/icons-material/ChevronRight";@@ -91,7 +91,7 @@ export const SubscriptionCardContentOverlay: React.FC<flexDirection={"column"}padding={"20px 16px"}>- {hasNonAdminFamilyMembers(userDetails.familyData) ? (+ {userDetails && isPartOfFamilyWithOtherMembers(userDetails) ? (<FamilySubscriptionCardContent userDetails={userDetails} />) : (<IndividualSubscriptionCardContentdiff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsxindex d5c5868011..a5165267cd 100644--- a/web/apps/photos/src/components/Sidebar/index.tsx+++ b/web/apps/photos/src/components/Sidebar/index.tsx@@ -158,8 +158,8 @@ const UserDetailsSection: React.FC<UserDetailsSectionProps> = ({const isMemberSubscription = useMemo(() =>userDetails &&- isPartOfFamily(userDetails.familyData) &&- !isFamilyAdmin(userDetails.familyData),+ isPartOfFamily(userDetails) &&+ !isFamilyAdmin(userDetails),[userDetails],);diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsxindex 63bf4eb61c..d594f790a4 100644--- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx@@ -1,5 +1,6 @@import { genericRetriableErrorDialogAttributes } from "@/base/components/utils/dialog";import log from "@/base/log";+import { useUserDetailsSnapshot } from "@/new/photos/components/utils/use-snapshot";import {getTotalFamilyUsage,isPartOfFamily,@@ -107,13 +108,8 @@ function PlanSelectorCard(props: PlanSelectorCardProps) {subscription?.period || "month",);const { showMiniDialog, setDialogMessage } = useContext(AppContext);- const bonusData = useMemo(() => {- const userDetails = getLocalUserDetails();- if (!userDetails) {- return null;- }- return userDetails.bonusData;- }, []);+ const bonusData = useUserDetailsSnapshot()?.bonusData;+const usage = useMemo(() => {const userDetails = getLocalUserDetails();@@ -913,7 +909,3 @@ const ManageSubscriptionButton = ({ children, ...props }: ButtonProps) => (<FluidContainer>{children}</FluidContainer></Button>);--function getLocalUserDetails(): UserDetails {- return getData(LS_KEYS.USER_DETAILS)?.value;-}diff --git a/web/packages/new/photos/services/family.ts b/web/packages/new/photos/services/family.tsindex dc4b5575b3..3ca86bf139 100644--- a/web/packages/new/photos/services/family.ts+++ b/web/packages/new/photos/services/family.ts@@ -9,6 +9,7 @@ import {} from "@ente/shared/storage/localStorage";import type { User } from "@ente/shared/user/types";import { z } from "zod";+import type { UserDetails } from "./user";const FamilyMember = z.object({/**@@ -55,30 +56,31 @@ export function getLocalFamilyData(): FamilyData {return getData(LS_KEYS.FAMILY_DATA);}-// isPartOfFamily return true if the current user is part of some family plan-export function isPartOfFamily(familyData: FamilyData): boolean {- return Boolean(- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain, @typescript-eslint/no-unnecessary-condition- familyData && familyData.members && familyData.members.length > 0,- );-}+/**+ * Return true if the user (represented by the given {@link userDetails}) is+ * part of a family plan.+ */+export const isPartOfFamily = (userDetails: UserDetails) =>+ (userDetails.familyData?.members.length ?? 0) > 0;-// hasNonAdminFamilyMembers return true if the admin user has members in his family-export function hasNonAdminFamilyMembers(familyData: FamilyData): boolean {- return Boolean(isPartOfFamily(familyData) && familyData.members.length > 1);-}+/**+ * Return true if the user (represented by the given {@link userDetails}) is+ * part of a family plan which has members in the family.+ */+export const isPartOfFamilyWithOtherMembers = (userDetails: UserDetails) =>+ (userDetails.familyData?.members.length ?? 0) > 1;-export function isFamilyAdmin(familyData: FamilyData): boolean {- const familyAdmin: FamilyMember = getFamilyPlanAdmin(familyData);+export function isFamilyAdmin(userDetails: UserDetails): boolean {+ const familyAdmin: FamilyMember = getFamilyPlanAdmin(userDetails);// eslint-disable-next-line @typescript-eslint/no-unsafe-assignmentconst user: User = getData(LS_KEYS.USER);return familyAdmin.email === user.email;}-export function getFamilyPlanAdmin(familyData: FamilyData): FamilyMember {- if (isPartOfFamily(familyData)) {- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion- return familyData.members.find((x) => x.isAdmin)!;+export function getFamilyPlanAdmin(userDetails: UserDetails): FamilyMember {+ if (isPartOfFamily(userDetails)) {+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain+ return userDetails.familyData?.members.find((x) => x.isAdmin)!;} else {log.error("invalid getFamilyPlanAdmin call - verify user is part of family plan before calling this method",@@ -89,12 +91,14 @@ export function getFamilyPlanAdmin(familyData: FamilyData): FamilyMember {}}-export function getTotalFamilyUsage(familyData: FamilyData): number {- return familyData.members.reduce(- (sum, currentMember) => sum + (currentMember.usage ?? 0),+/**+ * Return the combined usage of all the family members.+ */+export const familyUsage = (userDetails: UserDetails) =>+ (userDetails.familyData?.members ?? []).reduce(+ (sum, { usage }) => sum + (usage ?? 0),0,);-}export const leaveFamily = async () => {ensureOk(diff --git a/web/packages/new/photos/services/plan.ts b/web/packages/new/photos/services/plan.tsindex 93beff3e11..100b26768a 100644--- a/web/packages/new/photos/services/plan.ts+++ b/web/packages/new/photos/services/plan.ts@@ -4,6 +4,7 @@import { authenticatedRequestHeaders, ensureOk } from "@/base/http";import { apiURL, paymentsAppOrigin } from "@/base/origins";import {+ familyUsage,getTotalFamilyUsage,isPartOfFamily,} from "@/new/photos/services/family";@@ -81,6 +82,13 @@ export const getPlansData = async (): Promise<PlansData> => {return PlansData.parse(await res.json());};+/**+ * Derive the total usage for the user both when they are on an individual plan,+ * or on a family plan.+ */+export const planUsage = (userDetails: UserDetails) =>+ isPartOfFamily(userDetails) ? familyUsage(userDetails) : userDetails.usage;+const SubscriptionResponse = z.object({subscription: Subscription,});