Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Handle family email

Manav Rathief752a244c1d
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 1fea4027fb..fce8113997 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -77,7 +77,10 @@ import {
} from "ente-new/photos/components/gallery/reducer";
import { notifyOthersFilesDialogAttributes } from "ente-new/photos/components/utils/dialog-attributes";
import { useIsOffline } from "ente-new/photos/components/utils/use-is-offline";
-import { usePeopleStateSnapshot } from "ente-new/photos/components/utils/use-snapshot";
+import {
+ usePeopleStateSnapshot,
+ useUserDetailsSnapshot,
+} from "ente-new/photos/components/utils/use-snapshot";
import { shouldShowWhatsNew } from "ente-new/photos/services/changelog";
import {
addToFavoritesCollection,
@@ -110,7 +113,6 @@ import { initSettings } from "ente-new/photos/services/settings";
import {
redirectToCustomerPortal,
savedUserDetailsOrTriggerPull,
- userDetailsSnapshot,
verifyStripeSubscription,
} from "ente-new/photos/services/user-details";
import { usePhotosAppContext } from "ente-new/photos/types/context";
@@ -182,6 +184,7 @@ const Page: React.FC = () => {
EnteFile[]
>([]);
+ const userDetails = useUserDetailsSnapshot();
const peopleState = usePeopleStateSnapshot();
// The (non-sticky) header shown at the top of the gallery items.
@@ -352,6 +355,13 @@ const Page: React.FC = () => {
};
}, []);
+ useEffect(() => {
+ // Only act on updates after the initial mount has completed.
+ if (state.user && userDetails) {
+ dispatch({ type: "setUserDetails", userDetails });
+ }
+ }, [state.user, userDetails]);
+
useEffect(() => {
if (typeof activeCollectionID == "undefined" || !router.isReady) {
return;
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 56a2590ff0..d7aedfc0cb 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -38,7 +38,7 @@ import {
} from "../../services/collection-summary";
import type { PeopleState, Person } from "../../services/ml/people";
import type { SearchSuggestion } from "../../services/search/types";
-import type { FamilyData } from "../../services/user-details";
+import type { FamilyData, UserDetails } from "../../services/user-details";
/**
* Specifies what the bar at the top of the gallery is displaying currently.
@@ -455,6 +455,7 @@ export type GalleryAction =
collectionFiles: EnteFile[];
trashItems: TrashItem[];
}
+ | { type: "setUserDetails"; userDetails: UserDetails }
| { type: "setCollections"; collections: Collection[] }
| { type: "setCollectionFiles"; collectionFiles: EnteFile[] }
| { type: "uploadFile"; file: EnteFile }
@@ -623,6 +624,32 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
});
}
+ case "setUserDetails": {
+ // While user details have more state that can change, the only
+ // changes that affect the reducer's state (so far) are if the
+ // user's own email changes, or the list of their family members
+ // changes.
+ //
+ // Both of these affect only the list of share suggestion emails.
+
+ let user = state.user!;
+ const { email, familyData } = action.userDetails;
+ if (email != user.email) {
+ user = { ...user, email };
+ }
+
+ return {
+ ...state,
+ user,
+ familyData,
+ shareSuggestionEmails: createShareSuggestionEmails(
+ user,
+ familyData,
+ state.collections,
+ ),
+ };
+ }
+
case "setCollections": {
const collections = action.collections;