Skip to content

armgit / ente

Public Imported from GitHub
0

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

Forward

Manav Rathi3fdfb6c57d32
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index 367fea4b2d..45e9464e07 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -3,6 +3,7 @@ import FavoriteRoundedIcon from "@mui/icons-material/FavoriteRounded";
import PlayCircleOutlineOutlinedIcon from "@mui/icons-material/PlayCircleOutlineOutlined";
import { Box, Checkbox, Link, Typography, styled } from "@mui/material";
import Avatar from "components/pages/gallery/Avatar";
+import type { LocalUser } from "ente-accounts/services/user";
import { assertionFailed } from "ente-base/assert";
import { Overlay } from "ente-base/components/containers";
import { isSameDay } from "ente-base/date";
@@ -122,6 +123,14 @@ export interface FileListProps {
* another mode in which the gallery operates.
*/
modePlus?: GalleryBarMode | "search";
+ /**
+ * The logged in user, if any.
+ *
+ * This is only expected to be present when the listing is shown within the
+ * photos app, where we have a logged in user. The public albums app can
+ * omit this prop.
+ */
+ user?: LocalUser;
showAppDownloadBanner?: boolean;
/**
* If `true`, then the current listing is showing magic search results.
@@ -142,6 +151,13 @@ export interface FileListProps {
* Not set in the context of the shared albums app.
*/
favoriteFileIDs?: Set<number>;
+ /**
+ * A map from known Ente user IDs to their emails.
+ *
+ * This is only expected in the context of the photos app, and will be
+ * omitted when running in the public albums app.
+ */
+ emailByUserID?: Map<number, string>;
/**
* An optional {@link TimeStampListItem} shown before all the items in the
* list. It is not sticky, and scrolls along with the content of the list.
@@ -169,6 +185,7 @@ export const FileList: React.FC<FileListProps> = ({
width,
mode,
modePlus,
+ user,
annotatedFiles,
showAppDownloadBanner,
isMagicSearchResult,
@@ -178,6 +195,7 @@ export const FileList: React.FC<FileListProps> = ({
activeCollectionID,
activePersonID,
favoriteFileIDs,
+ emailByUserID,
header,
footer,
onItemClick,
@@ -711,7 +729,7 @@ export const FileList: React.FC<FileListProps> = ({
const handleSelectMulti = handleSelectCreatorMulti(
setSelected,
mode,
- galleryContext?.user?.id,
+ user?.id,
activeCollectionID,
activePersonID,
);
@@ -740,18 +758,12 @@ export const FileList: React.FC<FileListProps> = ({
handleSelectCreator(
setSelected,
mode,
- galleryContext.user?.id,
+ user?.id,
activeCollectionID,
activePersonID,
setRangeStart,
),
- [
- setSelected,
- mode,
- galleryContext.user?.id,
- activeCollectionID,
- activePersonID,
- ],
+ [setSelected, mode, user?.id, activeCollectionID, activePersonID],
);
const onHoverOver = (index: number) => () => {
@@ -816,6 +828,7 @@ export const FileList: React.FC<FileListProps> = ({
) => (
<FileThumbnail
key={`tile-${file.id}-selected-${selected[file.id] ?? false}`}
+ {...{ user, emailByUserID }}
file={file}
onClick={() => onItemClick(index)}
selectable={selectable}
@@ -1146,7 +1159,7 @@ const PhotoListRow = React.memo(
areEqual,
);
-interface FileThumbnailProps {
+type FileThumbnailProps = {
file: EnteFile;
onClick: () => void;
selectable: boolean;
@@ -1160,10 +1173,11 @@ interface FileThumbnailProps {
activeCollectionID: number;
showPlaceholder: boolean;
isFav: boolean;
-}
+} & Pick<FileListProps, "user" | "emailByUserID">;
const FileThumbnail: React.FC<FileThumbnailProps> = ({
file,
+ user,
onClick,
selectable,
selected,
@@ -1174,11 +1188,10 @@ const FileThumbnail: React.FC<FileThumbnailProps> = ({
isRangeSelectActive,
isInsSelectRange,
isFav,
+ emailByUserID,
activeCollectionID,
showPlaceholder,
}) => {
- const galleryContext = useContext(GalleryContext);
-
const [imageURL, setImageURL] = useState<string | undefined>(undefined);
const [isLongPressing, setIsLongPressing] = useState(false);
@@ -1282,9 +1295,9 @@ const FileThumbnail: React.FC<FileThumbnailProps> = ({
)
)}
{selected && <SelectedOverlay />}
- {shouldShowAvatar(file, galleryContext.user) && (
+ {shouldShowAvatar(file, user) && (
<AvatarOverlay>
- <Avatar file={file} />
+ <Avatar {...{ user, file, emailByUserID }} />
</AvatarOverlay>
)}
{isFav && (
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index d2c22ae352..419859052d 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -60,6 +60,7 @@ export type FileListWithViewerProps = {
| "activeCollectionID"
| "activePersonID"
| "favoriteFileIDs"
+ | "emailByUserID"
> &
Pick<
FileViewerProps,
@@ -97,6 +98,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
activeCollectionID,
activePersonID,
favoriteFileIDs,
+ emailByUserID,
isInIncomingSharedCollection,
isInHiddenSection,
fileNormalCollectionIDs,
@@ -176,6 +178,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
{...{
mode,
modePlus,
+ user,
showAppDownloadBanner,
isMagicSearchResult,
selectable,
@@ -184,6 +187,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
activeCollectionID,
activePersonID,
favoriteFileIDs,
+ emailByUserID
}}
onItemClick={handleThumbnailClick}
/>
diff --git a/web/apps/photos/src/components/pages/gallery/Avatar.tsx b/web/apps/photos/src/components/pages/gallery/Avatar.tsx
index 5342b73b5f..9fd056c6ae 100644
--- a/web/apps/photos/src/components/pages/gallery/Avatar.tsx
+++ b/web/apps/photos/src/components/pages/gallery/Avatar.tsx
@@ -1,4 +1,5 @@
import { styled } from "@mui/material";
+import type { LocalUser } from "ente-accounts/services/user";
import log from "ente-base/log";
import { EnteFile } from "ente-media/file";
import {
@@ -6,13 +7,14 @@ import {
avatarBackgroundColorPublicCollectedFile,
avatarTextColor,
} from "ente-new/photos/services/avatar";
-import { GalleryContext } from "pages/gallery";
-import React, { useContext, useLayoutEffect, useState } from "react";
+import React, { useLayoutEffect, useState } from "react";
interface AvatarProps {
+ user?: LocalUser;
file?: EnteFile;
email?: string;
opacity?: number;
+ emailByUserID?: Map<number, string>;
}
const AvatarBase = styled("div")<{
@@ -33,9 +35,13 @@ const AvatarBase = styled("div")<{
font-size: ${({ size }) => `${Math.floor(size / 2)}px`};
`;
-const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
- const { userIDToEmailMap, user } = useContext(GalleryContext);
-
+const Avatar: React.FC<AvatarProps> = ({
+ user,
+ file,
+ email,
+ opacity,
+ emailByUserID,
+}) => {
const [colorCode, setColorCode] = useState("");
const [userLetter, setUserLetter] = useState("");
@@ -46,7 +52,7 @@ const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
}
if (file.ownerID !== user.id) {
// getting email from in-memory id-email map
- const email = userIDToEmailMap.get(file.ownerID);
+ const email = emailByUserID.get(file.ownerID);
if (!email) {
log.error("email not found in userIDToEmailMap");
return;
@@ -80,8 +86,8 @@ const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
return;
}
- const id = Array.from(userIDToEmailMap.keys()).find(
- (key) => userIDToEmailMap.get(key) === email,
+ const id = Array.from(emailByUserID.keys()).find(
+ (key) => emailByUserID.get(key) === email,
);
if (!id) {
log.error(`ID not found for email: ${email}`);
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 16de25a02b..0ffa16bc90 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -1107,6 +1107,7 @@ const Page: React.FC = () => {
pendingFavoriteUpdates,
pendingVisibilityUpdates,
}}
+ emailByUserID={state.emailByUserID}
setFilesDownloadProgressAttributesCreator={
setFilesDownloadProgressAttributesCreator
}
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index 7f64d7d9d0..1dd2c1cc4f 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -1,4 +1,4 @@
-import type { User } from "ente-accounts/services/user";
+import type { LocalUser, User } from "ente-accounts/services/user";
import { joinPath } from "ente-base/file-name";
import log from "ente-base/log";
import { type Electron } from "ente-base/types/ipc";
@@ -312,7 +312,10 @@ export const getUserOwnedFiles = (files: EnteFile[]) => {
return files.filter((file) => file.ownerID === user.id);
};
-export const shouldShowAvatar = (file: EnteFile, user: User) => {
+export const shouldShowAvatar = (
+ file: EnteFile,
+ user: LocalUser | undefined,
+) => {
if (!file || !user) {
return false;
}
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 6febb458ea..5caff8447d 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -246,8 +246,9 @@ export interface GalleryState {
*/
fileNormalCollectionIDs: Map<number, number[]>;
/**
- * A map from Ente user IDs to their emails (except for the user in user
- * themselves).
+ * A map from known Ente user IDs to their emails
+ *
+ * This will not have an entry for the user themselves.
*
* This is used to perform a fast lookup of the email of the Ente user that
* shared a file or collection.