diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx index 698e15501c..cd1465f689 100644 --- a/web/apps/photos/src/pages/gallery.tsx +++ b/web/apps/photos/src/pages/gallery.tsx @@ -53,6 +53,10 @@ import { PeopleEmptyState, SearchResultsHeader, } from "ente-new/photos/components/gallery"; +import { + constructEmailList, + constructUserIDToEmailMap, +} from "ente-new/photos/components/gallery/helpers"; import { useGalleryReducer, type GalleryBarMode, @@ -107,8 +111,6 @@ import { FileWithPath } from "react-dropzone"; import { Trans } from "react-i18next"; import { addToFavorites, - constructEmailList, - constructUserIDToEmailMap, createAlbum, createUnCategorizedCollection, removeFromFavorites, diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts index b69697003f..5f761e20da 100644 --- a/web/apps/photos/src/services/collectionService.ts +++ b/web/apps/photos/src/services/collectionService.ts @@ -37,7 +37,6 @@ import { groupFilesByCollectionID, sortFiles, } from "ente-new/photos/services/files"; -import type { FamilyData } from "ente-new/photos/services/user-details"; import HTTPService from "ente-shared/network/HTTPService"; import { getData } from "ente-shared/storage/localStorage"; import { getToken } from "ente-shared/storage/localStorage/helpers"; @@ -724,58 +723,3 @@ export async function unhideToCollection( throw e; } } - -export const constructUserIDToEmailMap = ( - user: User, - collections: Collection[], -): Map => { - try { - const userIDToEmailMap = new Map(); - collections.forEach((item) => { - const { owner, sharees } = item; - if (user.id !== owner.id && owner.email) { - userIDToEmailMap.set(owner.id, owner.email); - } - if (sharees) { - sharees.forEach((item) => { - if (item.id !== user.id) - userIDToEmailMap.set(item.id, item.email); - }); - } - }); - return userIDToEmailMap; - } catch (e) { - log.error("Error Mapping UserId to email:", e); - return new Map(); - } -}; - -export const constructEmailList = ( - user: User, - collections: Collection[], - familyData: FamilyData, -): string[] => { - const emails = collections - .map((item) => { - const { owner, sharees } = item; - if (owner.email && item.owner.id !== user.id) { - return [item.owner.email]; - } else { - if (!sharees?.length) { - return []; - } - const shareeEmails = item.sharees - .filter((sharee) => sharee.email !== user.email) - .map((sharee) => sharee.email); - return shareeEmails; - } - }) - .flat(); - - // adding family members - if (familyData) { - const family = familyData.members.map((member) => member.email); - emails.push(...family); - } - return Array.from(new Set(emails)); -}; diff --git a/web/packages/new/photos/components/gallery/helpers.ts b/web/packages/new/photos/components/gallery/helpers.ts new file mode 100644 index 0000000000..59a0f33c4d --- /dev/null +++ b/web/packages/new/photos/components/gallery/helpers.ts @@ -0,0 +1,71 @@ +/** + * @file code that really belongs to pages/gallery.tsx itself, but it written + * here in a separate file so that we can write in this package that has + * TypeScript strict mode enabled. + * + * Once the original gallery.tsx is strict mode, this code can be inlined back + * there. + * + * Separate from index.tsx so that it can export non-(React-)components, which + * is a needed for fast refresh to work. + */ + +import log from "ente-base/log"; +import type { Collection } from "ente-media/collection"; +import type { FamilyData } from "ente-new/photos/services/user-details"; +import type { User } from "ente-shared/user/types"; + +export const constructUserIDToEmailMap = ( + user: User, + collections: Collection[], +): Map => { + try { + const userIDToEmailMap = new Map(); + collections.forEach((item) => { + const { owner, sharees } = item; + if (user.id !== owner.id && owner.email) { + userIDToEmailMap.set(owner.id, owner.email); + } + if (sharees) { + sharees.forEach((item) => { + if (item.id !== user.id) + userIDToEmailMap.set(item.id, item.email); + }); + } + }); + return userIDToEmailMap; + } catch (e) { + log.error("Error Mapping UserId to email:", e); + return new Map(); + } +}; + +export const constructEmailList = ( + user: User, + collections: Collection[], + familyData: FamilyData, +): string[] => { + const emails = collections + .map((item) => { + const { owner, sharees } = item; + if (owner.email && item.owner.id !== user.id) { + return [item.owner.email]; + } else { + if (!sharees?.length) { + return []; + } + const shareeEmails = item.sharees + .filter((sharee) => sharee.email !== user.email) + .map((sharee) => sharee.email); + return shareeEmails; + } + }) + .flat(); + + // adding family members + if (familyData) { + const family = familyData.members.map((member) => member.email); + emails.push(...family); + } + return Array.from(new Set(emails)); +};