π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add comments sidebar to file viewer
Anand Baburajan557bda93ce08
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex 3ad9216767..7e1c3ce740 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -289,6 +289,7 @@"people_suggestions_finding": "Finding similar faces...","people_suggestions_empty": "No more suggestions for now","info": "Info",+ "comments": "comments","file_name": "File name","caption_placeholder": "Add a description","location": "Location",diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsxnew file mode 100644index 0000000000..c950abf724--- /dev/null+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx@@ -0,0 +1,181 @@+import CloseIcon from "@mui/icons-material/Close";+import {+ Box,+ Drawer,+ IconButton,+ Stack,+ styled,+ TextField,+ Typography,+} from "@mui/material";+import { type ModalVisibilityProps } from "ente-base/components/utils/modal";+import { t } from "i18next";+import React, { useState } from "react";++const SendIcon: React.FC = () => (+ <svg+ width="18"+ height="16"+ viewBox="0 0 15 13"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M2.03872 4.50697L2.47372 5.26697C2.75072 5.75197 2.88872 5.99397 2.88872 6.25997C2.88872 6.52597 2.75072 6.76797 2.47372 7.25197L2.03872 8.01297C0.800717 10.18 0.181717 11.263 0.663717 11.801C1.14672 12.338 2.29072 11.838 4.57672 10.838L10.8527 8.09197C12.6477 7.30697 13.5457 6.91397 13.5457 6.25997C13.5457 5.60597 12.6477 5.21297 10.8527 4.42797L4.57672 1.68197C2.29072 0.681968 1.14672 0.181968 0.663717 0.718968C0.181717 1.25597 0.800717 2.33897 2.03872 4.50697Z"+ stroke="black"+ strokeOpacity="0.8"+ />+ </svg>+);++export type CommentsSidebarProps = ModalVisibilityProps;++/**+ * A sidebar panel for displaying and managing comments on a file.+ */+export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({+ open,+ onClose,+}) => {+ const [comment, setComment] = useState("");++ const handleSend = () => {+ if (!comment.trim()) return;++ // TODO: Call API to store comment+ setComment("");+ };++ return (+ <CommentsSidebarDrawer open={open} onClose={onClose} anchor="right">+ <Stack+ direction="row"+ sx={{+ alignItems: "center",+ justifyContent: "space-between",+ mb: 2,+ }}+ >+ <Typography sx={{ color: "#000", fontWeight: 600 }}>+ {`12 ${t("comments")}`}+ </Typography>+ <IconButton+ onClick={onClose}+ sx={{+ backgroundColor: "#F5F5F7",+ color: "#000",+ padding: "8px",+ "&:hover": {+ backgroundColor: "#E5E5E7",+ },+ }}+ >+ <CloseIcon sx={{ fontSize: 22 }} />+ </IconButton>+ </Stack>+ <Stack sx={{ flex: 1 }}>+ {/* Comments content will go here */}+ </Stack>+ <CommentInputContainer>+ <CommentInputWrapper>+ <CommentInput+ fullWidth+ multiline+ minRows={1}+ placeholder="Say something nice!"+ variant="standard"+ value={comment}+ onChange={(e) => setComment(e.target.value)}+ />+ </CommentInputWrapper>+ <IconButton+ sx={{+ position: "absolute",+ right: 12,+ bottom: 8.5,+ color: "#000",+ width: 42,+ height: 42,+ "&:hover": {+ backgroundColor: "rgba(0, 0, 0, 0.1)",+ },+ }}+ onClick={handleSend}+ >+ <SendIcon />+ </IconButton>+ </CommentInputContainer>+ </CommentsSidebarDrawer>+ );+};++const CommentsSidebarDrawer = styled(Drawer)(() => ({+ "& .MuiDrawer-paper": {+ width: "500px",+ maxWidth: "calc(100% - 32px)",+ height: "calc(100% - 32px)",+ margin: "16px",+ borderRadius: "36px",+ backgroundColor: "#fff",+ padding: "32px",+ boxShadow: "none",+ // Mobile view: full screen, no margin, no rounded corners+ "@media (max-width: 450px)": {+ width: "100%",+ maxWidth: "100%",+ height: "100%",+ margin: 0,+ borderRadius: 0,+ },+ },+ // No backdrop overlay+ "& .MuiBackdrop-root": {+ backgroundColor: "transparent",+ },+}));++const CommentInputContainer = styled(Box)(() => ({+ position: "relative",+ backgroundColor: "#F3F3F3",+ borderRadius: "20px",+ border: "2px solid rgba(0, 0, 0, 0.008)",+ margin: "-16px",+ marginTop: 0,+}));++const CommentInputWrapper = styled(Box)(() => ({+ padding: "8px 48px 8px 16px",+ maxHeight: "300px",+ overflow: "auto",+ "&::-webkit-scrollbar": {+ width: "8px",+ },+ "&::-webkit-scrollbar-track": {+ background: "transparent",+ },+ "&::-webkit-scrollbar-thumb": {+ background: "rgba(0, 0, 0, 0.3)",+ borderRadius: "4px",+ },+ "&::-webkit-scrollbar-thumb:hover": {+ background: "rgba(0, 0, 0, 0.5)",+ },+ scrollbarWidth: "thin",+ scrollbarColor: "rgba(0, 0, 0, 0.3) transparent",+}));++const CommentInput = styled(TextField)(() => ({+ "& .MuiInput-root": {+ "&::before, &::after": {+ display: "none",+ },+ },+ "& .MuiInputBase-input": {+ padding: 0,+ color: "#000",+ "&::placeholder": {+ color: "#666",+ opacity: 1,+ },+ },+}));diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex d025413d53..d8eef57e2a 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -54,6 +54,7 @@ import React, {useRef,useState,} from "react";+import { CommentsSidebar } from "./CommentsSidebar";import {fileInfoExifForFile,updateItemDataAlt,@@ -369,6 +370,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({>(undefined);const [openFileInfo, setOpenFileInfo] = useState(false);+ const [openComments, setOpenComments] = useState(false);const [moreMenuAnchorEl, setMoreMenuAnchorEl] =useState<HTMLElement | null>(null);const [openImageEditor, setOpenImageEditor] = useState(false);@@ -391,6 +393,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({return false;});setOpenFileInfo(false);+ setOpenComments(false);// No need to `resetMoreMenuButtonOnMenuClose` since we're closing// anyway and it'll be removed from the DOM.setMoreMenuAnchorEl(null);@@ -414,6 +417,10 @@ export const FileViewer: React.FC<FileViewerProps> = ({const handleFileInfoClose = useCallback(() => setOpenFileInfo(false), []);+ const handleViewComments = useCallback(() => setOpenComments(true), []);++ const handleCommentsClose = useCallback(() => setOpenComments(false), []);+// Callback invoked when the download action is triggered by activating the// download button in the PhotoSwipe bar.const handleDownloadBarAction = useCallback(@@ -672,6 +679,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({// Don't handle keydowns if any of the viewer's own modals are open.if (openFileInfo ||+ openComments ||!!moreMenuAnchorEl ||openImageEditor ||openConfirmDelete ||@@ -701,6 +709,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({return false;}, [openFileInfo,+ openComments,moreMenuAnchorEl,openImageEditor,openConfirmDelete,@@ -880,6 +889,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({},onAnnotate: handleAnnotate,onViewInfo: handleViewInfo,+ onViewComments: handleViewComments,onDownload: handleDownloadBarAction,onMore: handleMore,});@@ -909,6 +919,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({handleClose,handleAnnotate,handleViewInfo,+ handleViewComments,handleDownloadBarAction,handleMore,]);@@ -955,6 +966,10 @@ export const FileViewer: React.FC<FileViewerProps> = ({onSelectPerson={handleSelectPerson}{...{ collectionNameByID }}/>+ <CommentsSidebar+ open={openComments}+ onClose={handleCommentsClose}+ /><MoreMenuopen={!!moreMenuAnchorEl}onClose={handleMoreMenuCloseIfNeeded}diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.tsindex b85fb9cbdd..e9d0b08cb3 100644--- a/web/packages/gallery/components/viewer/photoswipe.ts+++ b/web/packages/gallery/components/viewer/photoswipe.ts@@ -139,6 +139,10 @@ type FileViewerPhotoSwipeOptions = Pick<* Called when the user activates the info action on a file.*/onViewInfo: (annotatedFile: FileViewerAnnotatedFile) => void;+ /**+ * Called when the user activates the comments action on a file.+ */+ onViewComments: () => void;/*** Called when the user activates the download action on a file.*/@@ -202,6 +206,7 @@ export class FileViewerPhotoSwipe {onClose,onAnnotate,onViewInfo,+ onViewComments,onDownload,onMore,}: FileViewerPhotoSwipeOptions) {@@ -1416,12 +1421,19 @@ export class FileViewerPhotoSwipe {const captionText = truncateCaptionIfNeeded(alt);captionEl.querySelector("p")!.innerText =captionText ?? "";- captionEl.style.display = captionText ? "block" : "none";+ captionEl.style.display = captionText+ ? "block"+ : "none";captionEl.classList.toggle("ente-video",fileType == FileType.video,);});+ // Wire up click handler for the comment button.+ const commentButton = element.querySelector<HTMLElement>(+ '.pswp__action-button[aria-label="Comment"]',+ );+ commentButton?.addEventListener("click", onViewComments);},});});