Skip to content

armgit / ente

Public Imported from GitHub
0

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

Implement likers list with real API data and album cover thumbnails

Anand Baburajan40dc86c60591
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index 945c9c6105..c4e23e17c9 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -78,6 +78,7 @@ export type FileListWithViewerProps = {
| "isInIncomingSharedCollection"
| "isInHiddenSection"
| "fileNormalCollectionIDs"
+ | "collectionSummaries"
| "collectionNameByID"
| "pendingFavoriteUpdates"
| "pendingVisibilityUpdates"
@@ -113,6 +114,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
isInIncomingSharedCollection,
isInHiddenSection,
fileNormalCollectionIDs,
+ collectionSummaries,
collectionNameByID,
pendingFavoriteUpdates,
pendingVisibilityUpdates,
@@ -221,6 +223,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
isInIncomingSharedCollection,
favoriteFileIDs,
fileNormalCollectionIDs,
+ collectionSummaries,
collectionNameByID,
pendingFavoriteUpdates,
pendingVisibilityUpdates,
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 0fadabf2bc..1e4bd49dc2 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -1403,6 +1403,7 @@ const Page: React.FC = () => {
pendingVisibilityUpdates,
onAddSaveGroup,
}}
+ collectionSummaries={normalCollectionSummaries}
emailByUserID={state.emailByUserID}
onToggleFavorite={handleFileViewerToggleFavorite}
onFileVisibilityUpdate={
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 5a6d5a3cc8..075a5931b7 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -47,6 +47,7 @@ import {
type ImageEditorOverlayProps,
} from "ente-new/photos/components/ImageEditorOverlay";
import { getCollectionByID } from "ente-new/photos/services/collection";
+import type { CollectionSummaries } from "ente-new/photos/services/collection-summary";
import {
addReaction,
deleteReaction,
@@ -214,6 +215,10 @@ export type FileViewerProps = ModalVisibilityProps & {
* that they are a part of.
*/
fileNormalCollectionIDs?: FileInfoProps["fileCollectionIDs"];
+ /**
+ * Collection summaries indexed by their IDs.
+ */
+ collectionSummaries?: CollectionSummaries;
/**
* Called when there was some update performed within the file viewer that
* necessitates us to pull the latest updates with remote.
@@ -324,6 +329,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
pendingFavoriteUpdates,
pendingVisibilityUpdates,
fileNormalCollectionIDs,
+ collectionSummaries,
collectionNameByID,
onTriggerRemotePull,
onRemoteFilesPull,
@@ -496,7 +502,8 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const collectionId = collectionIDs[0]!;
void (async () => {
try {
- const collection = await getCollectionByID(collectionId);
+ const collection =
+ await getCollectionByID(collectionId);
const reactionId = await addReaction(
collectionId,
fileId,
@@ -506,7 +513,9 @@ export const FileViewer: React.FC<FileViewerProps> = ({
log.info(`Added reaction: ${reactionId}`);
setFileReactions((prev) => {
const next = new Map(prev);
- next.set(fileId, [{ collectionId, reactionId }]);
+ next.set(fileId, [
+ { collectionId, reactionId },
+ ]);
return next;
});
} catch (e) {
@@ -523,7 +532,9 @@ export const FileViewer: React.FC<FileViewerProps> = ({
try {
for (const reaction of reactions) {
await deleteReaction(reaction.reactionId);
- log.info(`Deleted reaction: ${reaction.reactionId}`);
+ log.info(
+ `Deleted reaction: ${reaction.reactionId}`,
+ );
}
setFileReactions((prev) => {
const next = new Map(prev);
@@ -546,11 +557,15 @@ export const FileViewer: React.FC<FileViewerProps> = ({
void (async () => {
try {
await deleteReaction(existingReaction.reactionId);
- log.info(`Deleted reaction: ${existingReaction.reactionId}`);
+ log.info(
+ `Deleted reaction: ${existingReaction.reactionId}`,
+ );
setFileReactions((prev) => {
const next = new Map(prev);
const updated = (prev.get(fileId) ?? []).filter(
- (r) => r.reactionId !== existingReaction.reactionId,
+ (r) =>
+ r.reactionId !==
+ existingReaction.reactionId,
);
if (updated.length > 0) {
next.set(fileId, updated);
@@ -567,7 +582,8 @@ export const FileViewer: React.FC<FileViewerProps> = ({
// Not liked in this collection - add
void (async () => {
try {
- const collection = await getCollectionByID(activeCollectionID);
+ const collection =
+ await getCollectionByID(activeCollectionID);
const reactionId = await addReaction(
activeCollectionID,
fileId,
@@ -580,7 +596,10 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const existing = prev.get(fileId) ?? [];
next.set(fileId, [
...existing,
- { collectionId: activeCollectionID, reactionId },
+ {
+ collectionId: activeCollectionID,
+ reactionId,
+ },
]);
return next;
});
@@ -615,11 +634,15 @@ export const FileViewer: React.FC<FileViewerProps> = ({
void (async () => {
try {
await deleteReaction(reactionToDelete.reactionId);
- log.info(`Deleted reaction: ${reactionToDelete.reactionId}`);
+ log.info(
+ `Deleted reaction: ${reactionToDelete.reactionId}`,
+ );
setFileReactions((prev) => {
const next = new Map(prev);
const updated = (prev.get(fileId) ?? []).filter(
- (r) => r.reactionId !== reactionToDelete.reactionId,
+ (r) =>
+ r.reactionId !==
+ reactionToDelete.reactionId,
);
if (updated.length > 0) {
next.set(fileId, updated);
@@ -671,14 +694,21 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const fileId = file.id;
const collectionIDs = fileNormalCollectionIDs?.get(fileId) ?? [];
const existingReactions = fileReactionsRef.current.get(fileId) ?? [];
- const likedCollectionIDs = new Set(existingReactions.map((r) => r.collectionId));
+ const likedCollectionIDs = new Set(
+ existingReactions.map((r) => r.collectionId),
+ );
// Filter to only collections not already liked
- const collectionsToLike = collectionIDs.filter((id) => !likedCollectionIDs.has(id));
+ const collectionsToLike = collectionIDs.filter(
+ (id) => !likedCollectionIDs.has(id),
+ );
void (async () => {
try {
- const newReactions: { collectionId: number; reactionId: string }[] = [];
+ const newReactions: {
+ collectionId: number;
+ reactionId: string;
+ }[] = [];
for (const collectionId of collectionsToLike) {
const collection = await getCollectionByID(collectionId);
const reactionId = await addReaction(
@@ -935,7 +965,8 @@ export const FileViewer: React.FC<FileViewerProps> = ({
// Compute all albums the file belongs to and which are liked for the modal
const { allAlbumsForFile, likedAlbumIDs } = useMemo(() => {
const file = activeAnnotatedFile?.file;
- if (!file) return { allAlbumsForFile: [], likedAlbumIDs: new Set<number>() };
+ if (!file)
+ return { allAlbumsForFile: [], likedAlbumIDs: new Set<number>() };
// Get all collections the file belongs to
const collectionIDs = fileNormalCollectionIDs?.get(file.id) ?? [];
@@ -949,7 +980,12 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const likedAlbumIDs = new Set(reactions.map((r) => r.collectionId));
return { allAlbumsForFile, likedAlbumIDs };
- }, [activeAnnotatedFile, collectionNameByID, fileNormalCollectionIDs, fileReactions]);
+ }, [
+ activeAnnotatedFile,
+ collectionNameByID,
+ fileNormalCollectionIDs,
+ fileReactions,
+ ]);
const getFiles = useCallback(() => files, [files]);
@@ -1237,12 +1273,14 @@ export const FileViewer: React.FC<FileViewerProps> = ({
try {
if (isGalleryView) {
// Gallery view: check ALL collections the file belongs to
- const collectionIDs = fileNormalCollectionIDs?.get(activeFileID) ?? [];
+ const collectionIDs =
+ fileNormalCollectionIDs?.get(activeFileID) ?? [];
const foundReactions: FileReaction[] = [];
for (const collectionId of collectionIDs) {
try {
- const collection = await getCollectionByID(collectionId);
+ const collection =
+ await getCollectionByID(collectionId);
const reactions = await getFileReactions(
collectionId,
activeFileID,
@@ -1275,7 +1313,8 @@ export const FileViewer: React.FC<FileViewerProps> = ({
});
} else {
// Collection view: check only the active collection
- const collection = await getCollectionByID(activeCollectionID);
+ const collection =
+ await getCollectionByID(activeCollectionID);
const reactions = await getFileReactions(
activeCollectionID,
activeFileID,
@@ -1290,7 +1329,10 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const next = new Map(prev);
if (userReaction) {
next.set(activeFileID, [
- { collectionId: activeCollectionID, reactionId: userReaction.id },
+ {
+ collectionId: activeCollectionID,
+ reactionId: userReaction.id,
+ },
]);
} else {
next.delete(activeFileID);
@@ -1307,7 +1349,13 @@ export const FileViewer: React.FC<FileViewerProps> = ({
});
}
})();
- }, [open, activeFileID, activeCollectionID, fileNormalCollectionIDs, user?.id]);
+ }, [
+ open,
+ activeFileID,
+ activeCollectionID,
+ fileNormalCollectionIDs,
+ user?.id,
+ ]);
useEffect(() => {
if (open) {
@@ -1409,7 +1457,14 @@ export const FileViewer: React.FC<FileViewerProps> = ({
open={openComments}
onClose={handleCommentsClose}
/>
- <LikesSidebar open={openLikes} onClose={handleLikesClose} />
+ <LikesSidebar
+ open={openLikes}
+ onClose={handleLikesClose}
+ file={activeAnnotatedFile.file}
+ activeCollectionID={activeCollectionID}
+ fileNormalCollectionIDs={fileNormalCollectionIDs}
+ collectionSummaries={collectionSummaries}
+ />
<LikeAlbumSelectorModal
open={openLikeAlbumSelector}
onClose={handleLikeAlbumSelectorClose}
diff --git a/web/packages/gallery/components/viewer/LikesSidebar.tsx b/web/packages/gallery/components/viewer/LikesSidebar.tsx
index ee28869d93..45d22a1ad0 100644
--- a/web/packages/gallery/components/viewer/LikesSidebar.tsx
+++ b/web/packages/gallery/components/viewer/LikesSidebar.tsx
@@ -2,6 +2,7 @@ import CloseIcon from "@mui/icons-material/Close";
import {
Avatar,
Box,
+ CircularProgress,
Drawer,
IconButton,
Stack,
@@ -9,7 +10,16 @@ import {
Typography,
} from "@mui/material";
import { type ModalVisibilityProps } from "ente-base/components/utils/modal";
-import React, { useState } from "react";
+import log from "ente-base/log";
+import { downloadManager } from "ente-gallery/services/download";
+import type { EnteFile } from "ente-media/file";
+import { getCollectionByID } from "ente-new/photos/services/collection";
+import type { CollectionSummaries } from "ente-new/photos/services/collection-summary";
+import {
+ getFileReactions,
+ type Reaction,
+} from "ente-new/photos/services/reaction";
+import React, { useCallback, useEffect, useMemo, useState } from "react";
// =============================================================================
// Icons
@@ -54,70 +64,43 @@ const HeartFilledIcon: React.FC = () => (
// Types
// =============================================================================
+/** A liker with display info. */
interface Liker {
id: string;
+ userID: number;
userName: string;
- userAvatar?: string;
}
-interface Collection {
+/** Collection info for the dropdown. */
+interface CollectionInfo {
id: number;
name: string;
- coverURL?: string;
likeCount: number;
+ coverFile?: EnteFile;
}
-// =============================================================================
-// Constants
-// =============================================================================
-
-// Mock collections that contain this file
-const mockCollections: Collection[] = [
- {
- id: 1,
- name: "Mindfulness",
- coverURL:
- "https://images.unsplash.com/photo-1518531933037-91b2f5f229cc?w=100&h=100&fit=crop",
- likeCount: 6,
- },
- {
- id: 2,
- name: "Meditation",
- coverURL:
- "https://images.unsplash.com/photo-1518531933037-91b2f5f229cc?w=100&h=100&fit=crop",
- likeCount: 12,
- },
- {
- id: 3,
- name: "Gratitude",
- coverURL:
- "https://images.unsplash.com/photo-1518531933037-91b2f5f229cc?w=100&h=100&fit=crop",
- likeCount: 8,
- },
- {
- id: 4,
- name: "Self-Reflection",
- coverURL:
- "https://images.unsplash.com/photo-1518531933037-91b2f5f229cc?w=100&h=100&fit=crop",
- likeCount: 3,
- },
-];
-
-// Mock data - 6 dummy likers
-const mockLikers: Liker[] = [
- { id: "1", userName: "Vishnu" },
- { id: "2", userName: "Shanty" },
- { id: "3", userName: "Lakshmi" },
- { id: "4", userName: "Manav" },
- { id: "5", userName: "Saraswati" },
- { id: "6", userName: "Durga" },
-];
-
// =============================================================================
// Main Component
// =============================================================================
-export type LikesSidebarProps = ModalVisibilityProps;
+export interface LikesSidebarProps extends ModalVisibilityProps {
+ /**
+ * The file whose likes are being displayed.
+ */
+ file?: EnteFile;
+ /**
+ * The currently active collection ID (when viewing from within a collection).
+ */
+ activeCollectionID?: number;
+ /**
+ * A mapping from file IDs to the IDs of collections they belong to.
+ */
+ fileNormalCollectionIDs?: Map<number, number[]>;
+ /**
+ * Collection summaries indexed by their IDs.
+ */
+ collectionSummaries?: CollectionSummaries;
+}
/**
* A sidebar panel for displaying users who liked a file.
@@ -125,21 +108,233 @@ export type LikesSidebarProps = ModalVisibilityProps;
export const LikesSidebar: React.FC<LikesSidebarProps> = ({
open,
onClose,
+ file,
+ activeCollectionID,
+ fileNormalCollectionIDs,
+ collectionSummaries,
}) => {
- const [selectedCollection, setSelectedCollection] = useState<Collection>(
- mockCollections[0]!,
- );
+ const [loading, setLoading] = useState(false);
const [collectionDropdownOpen, setCollectionDropdownOpen] = useState(false);
- // Check if opened from a collection context (has ?collection=... or ?t=... in URL)
- // Public links use ?t= (access token) instead of ?collection=
+ // Reactions grouped by collection: collectionID -> reactions
+ const [reactionsByCollection, setReactionsByCollection] = useState<
+ Map<number, Reaction[]>
+ >(new Map());
+
+ // User ID to email mapping built from fetched collections
+ const [userIDToEmail, setUserIDToEmail] = useState<Map<number, string>>(
+ new Map(),
+ );
+
+ // Selected collection for viewing likes (when in gallery view)
+ const [selectedCollectionID, setSelectedCollectionID] = useState<
+ number | undefined
+ >(undefined);
+
+ // Thumbnail URLs for each collection's cover file: collectionID -> URL
+ const [thumbnailURLs, setThumbnailURLs] = useState<Map<number, string>>(
+ new Map(),
+ );
+
+ // Check if opened from a collection context
const hasCollectionContext =
- typeof window !== "undefined" &&
- (new URLSearchParams(window.location.search).has("collection") ||
- new URLSearchParams(window.location.search).has("t"));
+ activeCollectionID !== undefined && activeCollectionID !== 0;
+
+ // Get all collections the file belongs to
+ const fileCollectionIDs = useMemo(() => {
+ if (!file) return [];
+ return fileNormalCollectionIDs?.get(file.id) ?? [];
+ }, [file, fileNormalCollectionIDs]);
+
+ // Build collection info list with like counts and cover files
+ const collectionsInfo = useMemo((): CollectionInfo[] => {
+ return fileCollectionIDs.map((collectionID) => {
+ const summary = collectionSummaries?.get(collectionID);
+ return {
+ id: collectionID,
+ name: summary?.name ?? `Album ${collectionID}`,
+ likeCount:
+ reactionsByCollection
+ .get(collectionID)
+ ?.filter((r) => r.reactionType === "green_heart")
+ .length ?? 0,
+ coverFile: summary?.coverFile,
+ };
+ });
+ }, [fileCollectionIDs, collectionSummaries, reactionsByCollection]);
+
+ // Currently selected collection info
+ const selectedCollectionInfo = useMemo(() => {
+ const targetID = hasCollectionContext
+ ? activeCollectionID
+ : selectedCollectionID;
+ return (
+ collectionsInfo.find((c) => c.id === targetID) ?? collectionsInfo[0]
+ );
+ }, [
+ hasCollectionContext,
+ activeCollectionID,
+ selectedCollectionID,
+ collectionsInfo,
+ ]);
+
+ // Get likers for the selected collection
+ const likers = useMemo((): Liker[] => {
+ if (!selectedCollectionInfo) return [];
+ const reactions =
+ reactionsByCollection.get(selectedCollectionInfo.id) ?? [];
+ return reactions
+ .filter((r) => r.reactionType === "green_heart")
+ .map((r) => ({
+ id: r.id,
+ userID: r.userID,
+ userName: userIDToEmail.get(r.userID) ?? `User ${r.userID}`,
+ }));
+ }, [selectedCollectionInfo, reactionsByCollection, userIDToEmail]);
+
+ // Fetch reactions when the sidebar opens or file changes
+ const fetchReactions = useCallback(async () => {
+ if (!file || !open) return;
+
+ setLoading(true);
+ const newReactionsByCollection = new Map<number, Reaction[]>();
+ const newUserIDToEmail = new Map<number, string>();
+
+ try {
+ if (hasCollectionContext && activeCollectionID) {
+ // Collection view: only fetch for the active collection
+ const collection = await getCollectionByID(activeCollectionID);
+
+ // Build user ID to email map from collection owner and sharees
+ if (collection.owner.email) {
+ newUserIDToEmail.set(
+ collection.owner.id,
+ collection.owner.email,
+ );
+ }
+ for (const sharee of collection.sharees) {
+ if (sharee.email) {
+ newUserIDToEmail.set(sharee.id, sharee.email);
+ }
+ }
+
+ const reactions = await getFileReactions(
+ activeCollectionID,
+ file.id,
+ collection.key,
+ );
+ newReactionsByCollection.set(activeCollectionID, reactions);
+ } else {
+ // Gallery view: fetch for all collections the file belongs to
+ for (const collectionID of fileCollectionIDs) {
+ try {
+ const collection =
+ await getCollectionByID(collectionID);
+
+ // Build user ID to email map from collection owner and sharees
+ if (collection.owner.email) {
+ newUserIDToEmail.set(
+ collection.owner.id,
+ collection.owner.email,
+ );
+ }
+ for (const sharee of collection.sharees) {
+ if (sharee.email) {
+ newUserIDToEmail.set(sharee.id, sharee.email);
+ }
+ }
+
+ const reactions = await getFileReactions(
+ collectionID,
+ file.id,
+ collection.key,
+ );
+ newReactionsByCollection.set(collectionID, reactions);
+ } catch (e) {
+ log.error(
+ `Failed to fetch reactions for collection ${collectionID}`,
+ e,
+ );
+ }
+ }
+ }
+ setReactionsByCollection(newReactionsByCollection);
+ setUserIDToEmail(newUserIDToEmail);
+ } catch (e) {
+ log.error("Failed to fetch reactions", e);
+ } finally {
+ setLoading(false);
+ }
+ }, [
+ file,
+ open,
+ hasCollectionContext,
+ activeCollectionID,
+ fileCollectionIDs,
+ ]);
+
+ // Fetch reactions when the sidebar opens
+ useEffect(() => {
+ if (open) {
+ void fetchReactions();
+ }
+ }, [open, fetchReactions]);
+
+ // Set initial selected collection when file collection IDs are available
+ useEffect(() => {
+ if (
+ open &&
+ !hasCollectionContext &&
+ selectedCollectionID === undefined &&
+ fileCollectionIDs.length > 0
+ ) {
+ setSelectedCollectionID(fileCollectionIDs[0]);
+ }
+ }, [open, hasCollectionContext, selectedCollectionID, fileCollectionIDs]);
+
+ // Fetch thumbnails for each collection's cover file
+ useEffect(() => {
+ // Only fetch when open, don't clear when closing (avoids flash during animation)
+ if (!open || collectionsInfo.length === 0) {
+ return;
+ }
+
+ let didCancel = false;
+
+ const fetchThumbnails = async () => {
+ const urls = new Map<number, string>();
+ for (const collection of collectionsInfo) {
+ if (collection.coverFile) {
+ try {
+ const url =
+ await downloadManager.renderableThumbnailURL(
+ collection.coverFile,
+ );
+ if (!didCancel && url) {
+ urls.set(collection.id, url);
+ }
+ } catch (e) {
+ log.warn(
+ `Failed to fetch thumbnail for collection ${collection.id}`,
+ e,
+ );
+ }
+ }
+ }
+ if (!didCancel) {
+ setThumbnailURLs(urls);
+ }
+ };
- const handleCollectionSelect = (collection: Collection) => {
- setSelectedCollection(collection);
+ void fetchThumbnails();
+
+ return () => {
+ didCancel = true;
+ };
+ }, [open, collectionsInfo]);
+
+ const handleCollectionSelect = (collectionID: number) => {
+ setSelectedCollectionID(collectionID);
setCollectionDropdownOpen(false);
};
@@ -164,9 +359,11 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({
...theme.applyStyles("dark", { color: "#fff" }),
})}
>
- {`${mockLikers.length} likes`}
+ {loading
+ ? "Loading..."
+ : `${likers.length} ${likers.length === 1 ? "like" : "likes"}`}
</Typography>
- ) : (
+ ) : collectionsInfo.length > 1 ? (
<Box
sx={{
position: "relative",
@@ -181,12 +378,21 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({
}
>
<Box sx={{ position: "relative" }}>
- <CollectionThumbnail
- src={selectedCollection.coverURL}
- alt={selectedCollection.name}
- />
+ {selectedCollectionInfo &&
+ thumbnailURLs.get(
+ selectedCollectionInfo.id,
+ ) ? (
+ <CollectionThumbnail
+ src={thumbnailURLs.get(
+ selectedCollectionInfo.id,
+ )}
+ alt=""
+ />
+ ) : (
+ <CollectionThumbnailPlaceholder />
+ )}
<CollectionBadge>
- {selectedCollection.likeCount}
+ {selectedCollectionInfo?.likeCount ?? 0}
</CollectionBadge>
</Box>
<Typography
@@ -200,26 +406,34 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({
}),
})}
>
- {selectedCollection.name}
+ {selectedCollectionInfo?.name ?? "Album"}
</Typography>
<ChevronDownIcon />
</CollectionDropdownButton>
{collectionDropdownOpen && (
<CollectionDropdownMenu>
- {mockCollections.map((collection) => (
+ {collectionsInfo.map((collection) => (
<CollectionDropdownItem
key={collection.id}
onClick={() =>
handleCollectionSelect(
- collection,
+ collection.id,
)
}
>
<Box sx={{ position: "relative" }}>
- <CollectionThumbnail
- src={collection.coverURL}
- alt={collection.name}
- />
+ {thumbnailURLs.get(
+ collection.id,
+ ) ? (
+ <CollectionThumbnail
+ src={thumbnailURLs.get(
+ collection.id,
+ )}
+ alt=""
+ />
+ ) : (
+ <CollectionThumbnailPlaceholder />
+ )}
<CollectionBadge>
{collection.likeCount}
</CollectionBadge>
@@ -243,6 +457,18 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({
</CollectionDropdownMenu>
)}
</Box>
+ ) : (
+ <Typography
+ sx={(theme) => ({
+ color: "#000",
+ fontWeight: 600,
+ ...theme.applyStyles("dark", { color: "#fff" }),
+ })}
+ >
+ {loading
+ ? "Loading..."
+ : `${likers.length} ${likers.length === 1 ? "like" : "likes"}`}
+ </Typography>
)}
<CloseButton onClick={onClose}>
<CloseIcon sx={{ fontSize: 22 }} />
@@ -250,27 +476,36 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({
</Header>
<LikersContainer>
- {mockLikers.map((liker) => (
- <LikerRow key={liker.id}>
- <Avatar
- sx={(theme) => ({
- width: 32,
- height: 32,
- fontSize: 14,
- bgcolor: "#E0E0E0",
- color: "#666",
- ...theme.applyStyles("dark", {
- bgcolor: "rgba(255, 255, 255, 0.16)",
- color: "rgba(255, 255, 255, 0.7)",
- }),
- })}
- >
- {liker.userName[0]}
- </Avatar>
- <LikerName>{liker.userName}</LikerName>
- <HeartFilledIcon />
- </LikerRow>
- ))}
+ {loading ? (
+ <LoadingContainer>
+ <CircularProgress size={32} />
+ </LoadingContainer>
+ ) : likers.length === 0 ? (
+ <EmptyMessage>No likes yet</EmptyMessage>
+ ) : (
+ likers.map((liker) => (
+ <LikerRow key={liker.id}>
+ <Avatar
+ sx={(theme) => ({
+ width: 32,
+ height: 32,
+ fontSize: 14,
+ bgcolor: "#E0E0E0",
+ color: "#666",
+ ...theme.applyStyles("dark", {
+ bgcolor:
+ "rgba(255, 255, 255, 0.16)",
+ color: "rgba(255, 255, 255, 0.7)",
+ }),
+ })}
+ >
+ {liker.userName[0]?.toUpperCase() ?? "?"}
+ </Avatar>
+ <LikerName>{liker.userName}</LikerName>
+ <HeartFilledIcon />
+ </LikerRow>
+ ))
+ )}
</LikersContainer>
</DrawerContentWrapper>
</SidebarDrawer>
@@ -362,6 +597,12 @@ const CollectionThumbnail = styled("img")(() => ({
height: 24,
borderRadius: 5,
objectFit: "cover",
+}));
+
+const CollectionThumbnailPlaceholder = styled(Box)(() => ({
+ width: 24,
+ height: 24,
+ borderRadius: 5,
backgroundColor: "#08C225",
}));
@@ -454,6 +695,20 @@ const LikerName = styled(Typography)(({ theme }) => ({
...theme.applyStyles("dark", { color: "#fff" }),
}));
+const LoadingContainer = styled(Box)(() => ({
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
+ padding: "48px 0",
+}));
+
+const EmptyMessage = styled(Typography)(({ theme }) => ({
+ textAlign: "center",
+ padding: "48px 0",
+ color: "#666",
+ ...theme.applyStyles("dark", { color: "rgba(255, 255, 255, 0.5)" }),
+}));
+
// Context Menu Overlay
const ContextMenuOverlay = styled(Box)(() => ({
position: "absolute",