Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move fixed colors out of theme

Manav Rathie13797e02e9f
diff --git a/web/apps/photos/src/components/pages/gallery/Avatar.tsx b/web/apps/photos/src/components/pages/gallery/Avatar.tsx
index aa6772d9f6..f11c3fd400 100644
--- a/web/apps/photos/src/components/pages/gallery/Avatar.tsx
+++ b/web/apps/photos/src/components/pages/gallery/Avatar.tsx
@@ -1,6 +1,10 @@
import log from "@/base/log";
import { EnteFile } from "@/media/file";
-import { styled, useTheme } from "@mui/material";
+import {
+ avatarBackgroundColor,
+ avatarBackgroundColorPublicCollectedFile,
+} from "@/new/photos/services/avatar";
+import { styled } from "@mui/material";
import { GalleryContext } from "pages/gallery";
import React, { useContext, useLayoutEffect, useState } from "react";
@@ -10,8 +14,6 @@ interface AvatarProps {
opacity?: number;
}
-const PUBLIC_COLLECTED_FILES_AVATAR_COLOR_CODE = "#000000";
-
const AvatarBase = styled("div")<{
colorCode: string;
size: number;
@@ -32,7 +34,6 @@ const AvatarBase = styled("div")<{
const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
const { userIDToEmailMap, user } = useContext(GalleryContext);
- const theme = useTheme();
const [colorCode, setColorCode] = useState("");
const [userLetter, setUserLetter] = useState("");
@@ -49,11 +50,8 @@ const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
log.error("email not found in userIDToEmailMap");
return;
}
- const colorIndex =
- file.ownerID % theme.colors.avatarColors.length;
- const colorCode = theme.colors.avatarColors[colorIndex];
setUserLetter(email[0].toUpperCase());
- setColorCode(colorCode);
+ setColorCode(avatarBackgroundColor(file.ownerID));
} else if (file.ownerID === user.id) {
const uploaderName = file.pubMagicMetadata?.data.uploaderName;
if (!uploaderName) {
@@ -63,7 +61,7 @@ const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
return;
}
setUserLetter(uploaderName[0].toUpperCase());
- setColorCode(PUBLIC_COLLECTED_FILES_AVATAR_COLOR_CODE);
+ setColorCode(avatarBackgroundColorPublicCollectedFile);
}
} catch (e) {
log.error("AvatarIcon.tsx - useLayoutEffect file failed", e);
@@ -77,7 +75,7 @@ const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
}
if (user.email === email) {
setUserLetter(email[0].toUpperCase());
- setColorCode(PUBLIC_COLLECTED_FILES_AVATAR_COLOR_CODE);
+ setColorCode(avatarBackgroundColorPublicCollectedFile);
return;
}
@@ -88,10 +86,8 @@ const Avatar: React.FC<AvatarProps> = ({ file, email, opacity }) => {
log.error(`ID not found for email: ${email}`);
return;
}
- const colorIndex = id % theme.colors.avatarColors.length;
- const colorCode = theme.colors.avatarColors[colorIndex];
setUserLetter(email[0].toUpperCase());
- setColorCode(colorCode);
+ setColorCode(avatarBackgroundColor(id));
} catch (e) {
log.error("AvatarIcon.tsx - useLayoutEffect email failed", e);
}
diff --git a/web/packages/new/photos/services/avatar.ts b/web/packages/new/photos/services/avatar.ts
new file mode 100644
index 0000000000..9c5f8a0900
--- /dev/null
+++ b/web/packages/new/photos/services/avatar.ts
@@ -0,0 +1,59 @@
+/**
+ * The CSS color for the uploader indicator on a file that was uploaded to a
+ * public "collect" link that the user has created.
+ *
+ * Such files belong to the user, even if they were uploaded by someone on their
+ * behalf, and are thus marked differently (in this case, colorlessly) than
+ * other shared files.
+ *
+ * This is a hex string, suitable for being used in CSS.
+ */
+export const avatarBackgroundColorPublicCollectedFile = "#000000";
+
+/**
+ * The ordered list of CSS colors for the owner indicator avatar background on
+ * files that the user does not own in shared albums.
+ *
+ * Each entry is a hex string, suitable for being used in CSS.
+ */
+const avatarBackgroundColors = [
+ "#76549A",
+ "#DF7861",
+ "#94B49F",
+ "#87A2FB",
+ "#C689C6",
+ "#937DC2",
+ "#325288",
+ "#85B4E0",
+ "#C1A3A3",
+ "#E1A059",
+ "#426165",
+ "#6B77B2",
+ "#957FEF",
+ "#DD9DE2",
+ "#82AB8B",
+ "#9BBBE8",
+ "#8FBEBE",
+ "#8AC3A1",
+ "#A8B0F2",
+ "#B0C695",
+ "#E99AAD",
+ "#D18484",
+ "#78B5A7",
+];
+
+/**
+ * Return the CSS color to use as the background of the avatar indicating the
+ * owner of a shared file.
+ *
+ * @param ownerID The user ID of the user who owns that file.
+ *
+ * Note that for the files in shared albums uploaded via collect links, while we
+ * do show an avatar / uploader indicator, but these should use
+ * {@link avatarBackgroundColorPublicCollectedFile}.
+ *
+ * @returns A a hex string, suitable for being used in CSS as the color of the
+ * owner avatar indicator atop item thumbnails.
+ */
+export const avatarBackgroundColor = (ownerID: number) =>
+ avatarBackgroundColors[ownerID % avatarBackgroundColors.length]!;
diff --git a/web/packages/shared/themes/colors.ts b/web/packages/shared/themes/colors.ts
index 2ba1a3dad3..2a6d353ca7 100644
--- a/web/packages/shared/themes/colors.ts
+++ b/web/packages/shared/themes/colors.ts
@@ -127,31 +127,6 @@ const lightThemeColors: Omit<ThemeColorsOptions, keyof FixedColors> = {
},
],
},
- avatarColors: [
- "#76549A",
- "#DF7861",
- "#94B49F",
- "#87A2FB",
- "#C689C6",
- "#937DC2",
- "#325288",
- "#85B4E0",
- "#C1A3A3",
- "#E1A059",
- "#426165",
- "#6B77B2",
- "#957FEF",
- "#DD9DE2",
- "#82AB8B",
- "#9BBBE8",
- "#8FBEBE",
- "#8AC3A1",
- "#A8B0F2",
- "#B0C695",
- "#E99AAD",
- "#D18484",
- "#78B5A7",
- ],
};
const darkThemeColors: Omit<ThemeColorsOptions, keyof FixedColors> = {
@@ -215,29 +190,4 @@ const darkThemeColors: Omit<ThemeColorsOptions, keyof FixedColors> = {
},
],
},
- avatarColors: [
- "#76549A",
- "#DF7861",
- "#94B49F",
- "#87A2FB",
- "#C689C6",
- "#937DC2",
- "#325288",
- "#85B4E0",
- "#C1A3A3",
- "#E1A059",
- "#426165",
- "#6B77B2",
- "#957FEF",
- "#DD9DE2",
- "#82AB8B",
- "#9BBBE8",
- "#8FBEBE",
- "#8AC3A1",
- "#A8B0F2",
- "#B0C695",
- "#E99AAD",
- "#D18484",
- "#78B5A7",
- ],
};
diff --git a/web/packages/shared/themes/mui-theme.d.ts b/web/packages/shared/themes/mui-theme.d.ts
index 0c9dfeb46e..5381d33eb6 100644
--- a/web/packages/shared/themes/mui-theme.d.ts
+++ b/web/packages/shared/themes/mui-theme.d.ts
@@ -116,7 +116,6 @@ declare module "@mui/material/styles" {
blur: BlurStrength;
white: Omit<Strength, "faint">;
black: Omit<Strength, "faint">;
- avatarColors: AvatarColors;
}
interface ThemeColorsOptions {
@@ -132,7 +131,6 @@ declare module "@mui/material/styles" {
blur?: Partial<BlurStrength>;
white?: Partial<Omit<Strength, "faint">>;
black?: Partial<Omit<Strength, "faint">>;
- avatarColors?: Partial<AvatarColors>;
}
interface ColorStrength {
@@ -187,7 +185,5 @@ declare module "@mui/material/styles" {
muted: number;
faint: number;
}
-
- type AvatarColors = string[];
}
export {};