Skip to content

armgit / ente

Public Imported from GitHub
0

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

Tweak

Manav Rathi579afbd6b550
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index cd1465f689..8d82280fb3 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -54,8 +54,8 @@ import {
SearchResultsHeader,
} from "ente-new/photos/components/gallery";
import {
- constructEmailList,
constructUserIDToEmailMap,
+ createShareeSuggestionEmails,
} from "ente-new/photos/components/gallery/helpers";
import {
useGalleryReducer,
@@ -365,23 +365,10 @@ const Page: React.FC = () => {
if (!user || !normalCollections) {
return;
}
- const userIdToEmailMap = constructUserIDToEmailMap(
- user,
- normalCollections,
+ setUserIDToEmailMap(constructUserIDToEmailMap(user, normalCollections));
+ setEmailList(
+ createShareeSuggestionEmails(user, normalCollections, familyData),
);
- setUserIDToEmailMap(userIdToEmailMap);
- }, [user, normalCollections]);
-
- useEffect(() => {
- if (!user || !normalCollections) {
- return;
- }
- const emailList = constructEmailList(
- user,
- normalCollections,
- familyData,
- );
- setEmailList(emailList);
}, [user, normalCollections, familyData]);
useEffect(() => {
diff --git a/web/packages/new/photos/components/gallery/helpers.ts b/web/packages/new/photos/components/gallery/helpers.ts
index 1df2bb4bc1..6d7a6657f4 100644
--- a/web/packages/new/photos/components/gallery/helpers.ts
+++ b/web/packages/new/photos/components/gallery/helpers.ts
@@ -38,34 +38,34 @@ export const constructUserIDToEmailMap = (
return userIDToEmailMap;
};
-export const constructEmailList = (
+/**
+ * Create a list of emails that are shown as suggestions to the user when they
+ * are trying to share albums with specific users.
+ */
+export const createShareeSuggestionEmails = (
user: User,
collections: Collection[],
familyData: FamilyData | undefined,
): string[] => {
const emails = collections
- .map((item) => {
- const { owner, sharees } = item;
- if (owner.email && item.owner.id !== user.id) {
- return [item.owner.email];
+ .map(({ owner, sharees }) => {
+ if (owner.email && owner.id !== user.id) {
+ return [owner.email];
} else {
// Not sure about its nullability currently, revisit after auditing the
// type for Collection.
//
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
- if (!sharees?.length) {
- return [];
- }
- const shareeEmails = item.sharees.map((sharee) => sharee.email);
- return shareeEmails;
+ return (sharees ?? []).map((sharee) => sharee.email);
}
})
.flat();
- // adding family members
+ // Add family members.
if (familyData) {
const family = familyData.members.map((member) => member.email);
emails.push(...family);
}
- return Array.from(new Set(emails.filter((email) => email !== user.email)));
+
+ return [...new Set(emails.filter((email) => email !== user.email))];
};