π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add likes sidebar to file viewer with right-click on heart icon
Anand Baburajan7b02ec742f36
diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsxindex ecd63e57f3..dad491ede7 100644--- a/web/packages/gallery/components/viewer/CommentsSidebar.tsx+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx@@ -135,7 +135,6 @@ interface Collection {// Mock current user ID (for determining if comment is from current user)const CURRENT_USER_ID = 2;-// Mock collections that contain this fileconst mockCollections: Collection[] = [{diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex d8eef57e2a..ddacfc1e1a 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -60,6 +60,7 @@ import {updateItemDataAlt,type ItemData,} from "./data-source";+import { LikesSidebar } from "./LikesSidebar";import {FileViewerPhotoSwipe,moreButtonID,@@ -371,6 +372,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({const [openFileInfo, setOpenFileInfo] = useState(false);const [openComments, setOpenComments] = useState(false);+ const [openLikes, setOpenLikes] = useState(false);const [moreMenuAnchorEl, setMoreMenuAnchorEl] =useState<HTMLElement | null>(null);const [openImageEditor, setOpenImageEditor] = useState(false);@@ -394,6 +396,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({});setOpenFileInfo(false);setOpenComments(false);+ setOpenLikes(false);// No need to `resetMoreMenuButtonOnMenuClose` since we're closing// anyway and it'll be removed from the DOM.setMoreMenuAnchorEl(null);@@ -421,6 +424,10 @@ export const FileViewer: React.FC<FileViewerProps> = ({const handleCommentsClose = useCallback(() => setOpenComments(false), []);+ const handleViewLikes = useCallback(() => setOpenLikes(true), []);++ const handleLikesClose = useCallback(() => setOpenLikes(false), []);+// Callback invoked when the download action is triggered by activating the// download button in the PhotoSwipe bar.const handleDownloadBarAction = useCallback(@@ -680,6 +687,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({if (openFileInfo ||openComments ||+ openLikes ||!!moreMenuAnchorEl ||openImageEditor ||openConfirmDelete ||@@ -710,6 +718,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({}, [openFileInfo,openComments,+ openLikes,moreMenuAnchorEl,openImageEditor,openConfirmDelete,@@ -890,6 +899,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({onAnnotate: handleAnnotate,onViewInfo: handleViewInfo,onViewComments: handleViewComments,+ onViewLikes: handleViewLikes,onDownload: handleDownloadBarAction,onMore: handleMore,});@@ -920,6 +930,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({handleAnnotate,handleViewInfo,handleViewComments,+ handleViewLikes,handleDownloadBarAction,handleMore,]);@@ -970,6 +981,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({open={openComments}onClose={handleCommentsClose}/>+ <LikesSidebar open={openLikes} onClose={handleLikesClose} /><MoreMenuopen={!!moreMenuAnchorEl}onClose={handleMoreMenuCloseIfNeeded}diff --git a/web/packages/gallery/components/viewer/LikesSidebar.tsx b/web/packages/gallery/components/viewer/LikesSidebar.tsxnew file mode 100644index 0000000000..b1582d0518--- /dev/null+++ b/web/packages/gallery/components/viewer/LikesSidebar.tsx@@ -0,0 +1,419 @@+import CloseIcon from "@mui/icons-material/Close";+import {+ Avatar,+ Box,+ Drawer,+ IconButton,+ Stack,+ styled,+ Typography,+} from "@mui/material";+import { type ModalVisibilityProps } from "ente-base/components/utils/modal";+import React, { useState } from "react";++// =============================================================================+// Icons+// =============================================================================++const ChevronDownIcon: React.FC = () => (+ <svg+ width="22"+ height="22"+ viewBox="0 0 20 20"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ style={{ marginLeft: -6 }}+ >+ <path+ d="M10.0007 12.5004L6.46484 8.96544L7.64401 7.78711L10.0007 10.1438L12.3573 7.78711L13.5365 8.96544L10.0007 12.5004Z"+ fill="black"+ />+ </svg>+);++const HeartFilledIcon: React.FC = () => (+ <svg+ width="18"+ height="16"+ viewBox="0 0 30 26"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M12.4926 23.4794C8.64537 20.6025 1.02344 14.0254 1.02344 8.10676C1.02344 4.19475 3.89425 1.02344 7.84162 1.02344C9.88707 1.02344 11.9325 1.70526 14.6598 4.43253C17.3871 1.70526 19.4325 1.02344 21.478 1.02344C25.4253 1.02344 28.2962 4.19475 28.2962 8.10676C28.2962 14.0254 20.6743 20.6025 16.827 23.4794C15.5324 24.4474 13.7872 24.4474 12.4926 23.4794Z"+ fill="#08C225"+ stroke="#08C225"+ strokeWidth="2.04545"+ strokeLinecap="round"+ strokeLinejoin="round"+ />+ </svg>+);++// =============================================================================+// Types+// =============================================================================++interface Liker {+ id: string;+ userName: string;+ userAvatar?: string;+}++interface Collection {+ id: number;+ name: string;+ coverURL?: string;+ likeCount: number;+}++// =============================================================================+// 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;++/**+ * A sidebar panel for displaying users who liked a file.+ */+export const LikesSidebar: React.FC<LikesSidebarProps> = ({+ open,+ onClose,+}) => {+ const [selectedCollection, setSelectedCollection] = useState<Collection>(+ mockCollections[0]!,+ );+ const [collectionDropdownOpen, setCollectionDropdownOpen] = useState(false);++ // Check if opened from a collection (has ?collection=... in URL)+ const hasCollectionContext =+ typeof window !== "undefined" &&+ new URLSearchParams(window.location.search).has("collection");++ const handleCollectionSelect = (collection: Collection) => {+ setSelectedCollection(collection);+ setCollectionDropdownOpen(false);+ };++ const showOverlay = collectionDropdownOpen;++ return (+ <SidebarDrawer open={open} onClose={onClose} anchor="right">+ <DrawerContentWrapper>+ {showOverlay && (+ <ContextMenuOverlay+ onClick={() => {+ setCollectionDropdownOpen(false);+ }}+ />+ )}+ <Header>+ {hasCollectionContext ? (+ <Typography sx={{ color: "#000", fontWeight: 600 }}>+ {`${mockLikers.length} likes`}+ </Typography>+ ) : (+ <Box+ sx={{+ position: "relative",+ zIndex: collectionDropdownOpen ? 12 : "auto",+ }}+ >+ <CollectionDropdownButton+ onClick={() =>+ setCollectionDropdownOpen(+ !collectionDropdownOpen,+ )+ }+ >+ <Box sx={{ position: "relative" }}>+ <CollectionThumbnail+ src={selectedCollection.coverURL}+ alt={selectedCollection.name}+ />+ <CollectionBadge>+ {selectedCollection.likeCount}+ </CollectionBadge>+ </Box>+ <Typography+ sx={{+ color: "#000",+ fontWeight: 600,+ fontSize: 14,+ lineHeight: "20px",+ }}+ >+ {selectedCollection.name}+ </Typography>+ <ChevronDownIcon />+ </CollectionDropdownButton>+ {collectionDropdownOpen && (+ <CollectionDropdownMenu>+ {mockCollections.map((collection) => (+ <CollectionDropdownItem+ key={collection.id}+ onClick={() =>+ handleCollectionSelect(+ collection,+ )+ }+ >+ <Box sx={{ position: "relative" }}>+ <CollectionThumbnail+ src={collection.coverURL}+ alt={collection.name}+ />+ <CollectionBadge>+ {collection.likeCount}+ </CollectionBadge>+ </Box>+ <Typography+ sx={{+ color: "#000",+ fontWeight: 600,+ fontSize: 14,+ lineHeight: "20px",+ }}+ >+ {collection.name}+ </Typography>+ </CollectionDropdownItem>+ ))}+ </CollectionDropdownMenu>+ )}+ </Box>+ )}+ <CloseButton onClick={onClose}>+ <CloseIcon sx={{ fontSize: 22 }} />+ </CloseButton>+ </Header>++ <LikersContainer>+ {mockLikers.map((liker) => (+ <LikerRow key={liker.id}>+ <Avatar+ sx={{+ width: 32,+ height: 32,+ fontSize: 14,+ bgcolor: "#E0E0E0",+ color: "#666",+ }}+ >+ {liker.userName[0]}+ </Avatar>+ <LikerName>{liker.userName}</LikerName>+ <HeartFilledIcon />+ </LikerRow>+ ))}+ </LikersContainer>+ </DrawerContentWrapper>+ </SidebarDrawer>+ );+};++// =============================================================================+// Styled Components+// =============================================================================++// Drawer & Layout+const SidebarDrawer = styled(Drawer)(() => ({+ "& .MuiDrawer-paper": {+ width: "23vw",+ minWidth: "520px",+ maxWidth: "calc(100% - 32px)",+ height: "calc(100% - 32px)",+ margin: "16px",+ borderRadius: "36px",+ backgroundColor: "#fff",+ padding: "24px 24px 32px 24px",+ boxShadow: "none",+ display: "flex",+ flexDirection: "column",+ "@media (max-width: 450px)": {+ width: "100%",+ minWidth: "unset",+ maxWidth: "100%",+ height: "100%",+ margin: 0,+ borderRadius: 0,+ },+ },+ "& .MuiBackdrop-root": { backgroundColor: "transparent" },+}));++const DrawerContentWrapper = styled(Box)(() => ({+ position: "relative",+ display: "flex",+ flexDirection: "column",+ flex: 1,+ minHeight: 0,+}));++const Header = styled(Stack)(() => ({+ flexDirection: "row",+ alignItems: "center",+ justifyContent: "space-between",+ marginBottom: 48,+}));++const CloseButton = styled(IconButton)(() => ({+ backgroundColor: "#F5F5F7",+ color: "#000",+ padding: "8px",+ "&:hover": { backgroundColor: "#E5E5E7" },+}));++// Collection Dropdown+const CollectionDropdownButton = styled(Box)(() => ({+ display: "inline-flex",+ alignItems: "center",+ justifyContent: "center",+ gap: 14,+ padding: "6px 6px 3px 6px",+ borderRadius: 12,+ backgroundColor: "#F0F0F0",+ cursor: "pointer",+ "&:hover": { backgroundColor: "#E8E8E8" },+}));++const CollectionThumbnail = styled("img")(() => ({+ width: 24,+ height: 24,+ borderRadius: 5,+ objectFit: "cover",+ backgroundColor: "#08C225",+}));++const CollectionBadge = styled(Box)(() => ({+ position: "absolute",+ bottom: 2,+ right: -4,+ display: "inline-flex",+ padding: "3px 5px",+ justifyContent: "center",+ alignItems: "center",+ borderRadius: 34,+ backgroundColor: "#FFF",+ color: "#000",+ fontSize: 10,+ fontWeight: 600,+ lineHeight: 1,+ minWidth: 14,+}));++const CollectionDropdownMenu = styled(Box)(() => ({+ position: "absolute",+ top: "calc(100% + 8px)",+ left: 0,+ display: "flex",+ flexDirection: "column",+ justifyContent: "center",+ alignItems: "flex-start",+ width: 184,+ padding: 6,+ gap: 12,+ borderRadius: 12,+ border: "1px solid rgba(0, 0, 0, 0.08)",+ backgroundColor: "#F0F0F0",+ zIndex: 12,+}));++const CollectionDropdownItem = styled(Box)(() => ({+ display: "flex",+ alignItems: "center",+ gap: 14,+ padding: "6px 6px 3px 6px",+ borderRadius: 8,+ cursor: "pointer",+ width: "100%",+ "&:hover": { backgroundColor: "#E8E8E8" },+}));++const LikersContainer = styled(Box)(() => ({+ flex: 1,+ overflow: "auto",+ marginRight: -24,+ paddingRight: 24,+ "&::-webkit-scrollbar": { width: "6px" },+ "&::-webkit-scrollbar-track": { background: "transparent" },+ "&::-webkit-scrollbar-thumb": {+ background: "rgba(0, 0, 0, 0.2)",+ borderRadius: "3px",+ },+ scrollbarWidth: "thin",+ scrollbarColor: "rgba(0, 0, 0, 0.2) transparent",+}));++const LikerRow = styled(Box)(() => ({+ display: "flex",+ alignItems: "center",+ gap: 12,+ padding: "10px 10px 10px 0",+}));++const LikerName = styled(Typography)(() => ({+ flex: 1,+ fontWeight: 500,+ color: "#000",+ fontSize: 14,+}));++// Context Menu Overlay+const ContextMenuOverlay = styled(Box)(() => ({+ position: "absolute",+ top: -24,+ left: -24,+ right: -24,+ bottom: -32,+ backgroundColor: "rgba(0, 0, 0, 0.6)",+ zIndex: 10,+ borderRadius: "36px",+ "@media (max-width: 450px)": { borderRadius: 0 },+}));diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.tsindex 70770af045..bbf5cdf32f 100644--- a/web/packages/gallery/components/viewer/photoswipe.ts+++ b/web/packages/gallery/components/viewer/photoswipe.ts@@ -143,6 +143,10 @@ type FileViewerPhotoSwipeOptions = Pick<* Called when the user activates the comments action on a file.*/onViewComments: () => void;+ /**+ * Called when the user activates the likes action on a file (right-click on heart).+ */+ onViewLikes: () => void;/*** Called when the user activates the download action on a file.*/@@ -207,6 +211,7 @@ export class FileViewerPhotoSwipe {onAnnotate,onViewInfo,onViewComments,+ onViewLikes,onDownload,onMore,}: FileViewerPhotoSwipeOptions) {@@ -1434,6 +1439,14 @@ export class FileViewerPhotoSwipe {'.pswp__action-button[aria-label="Comment"]',);commentButton?.addEventListener("click", onViewComments);+ // Wire up right-click handler for the like button to open likes sidebar.+ const likeButton = element.querySelector<HTMLElement>(+ '.pswp__action-button[aria-label="Like"]',+ );+ likeButton?.addEventListener("contextmenu", (e) => {+ e.preventDefault();+ onViewLikes();+ });},});});