This commit is contained in:
Manav Rathi
2025-03-05 07:53:51 +05:30
parent 8f8cdbb13f
commit 1bc8c44b54
2 changed files with 44 additions and 14 deletions

View File

@@ -37,6 +37,7 @@ import {
ImageEditorOverlay,
type ImageEditorOverlayProps,
} from "@/new/photos/components/ImageEditorOverlay";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
@@ -338,8 +339,7 @@ const FileViewer: React.FC<FileViewerProps> = ({
: undefined;
}, [onDelete, showConfirmDelete, handleMoreMenuClose]);
// Not memoized since it depends on the frequently changing
// `activeAnnotatedFile`.
// Not memoized since it uses the frequently changing `activeAnnotatedFile`.
const handleDelete = async () => {
const file = activeAnnotatedFile!.file;
await onDelete(file);
@@ -364,6 +364,11 @@ const FileViewer: React.FC<FileViewerProps> = ({
});
};
// Not memoized since it uses the frequently changing `activeAnnotatedFile`.
const handleCopyImage = () => {
console.log("TODO copy", activeAnnotatedFile!);
};
const handleEditImage = useMemo(() => {
return onSaveEditedImageCopy
? () => {
@@ -388,10 +393,9 @@ const FileViewer: React.FC<FileViewerProps> = ({
const handleAnnotate = useCallback(
(file: EnteFile): FileViewerFileAnnotation => {
log.debug(() => ["viewer", { action: "annotate", file }]);
const fileID = file.id;
const isOwnFile = file.ownerID == user?.id;
const canModify =
isOwnFile && !isInTrashSection && !isInHiddenSection;
const showFavorite = canModify;
@@ -413,16 +417,30 @@ const FileViewer: React.FC<FileViewerProps> = ({
}
})();
const showCopyImage = (() => {
switch (file.metadata.fileType) {
case FileType.image:
case FileType.livePhoto:
return true;
default:
return false;
}
})();
const showMore =
showDelete || showEditImage || showDownload == "menu";
showDownload == "menu" ||
showDelete ||
showCopyImage ||
showEditImage;
return {
fileID,
isOwnFile,
showFavorite,
showDownload,
showMore,
showDelete,
showDownload,
showCopyImage,
showEditImage,
};
},
@@ -602,6 +620,14 @@ const FileViewer: React.FC<FileViewerProps> = ({
<DeleteIcon />
</MoreMenuItem>
)}
{activeAnnotatedFile?.annotation.showCopyImage && (
<MoreMenuItem onClick={handleCopyImage}>
<Typography sx={{ fontWeight: "medium" }}>
{/*TODO */ pt("Copy image")}
</Typography>
<ContentCopyIcon />
</MoreMenuItem>
)}
{activeAnnotatedFile?.annotation.showEditImage && (
<MoreMenuItem onClick={handleEditImage}>
<Typography sx={{ fontWeight: "medium" }}>

View File

@@ -53,14 +53,6 @@ export interface FileViewerFileAnnotation {
* `true` if the toggle favorite action should be shown for this file.
*/
showFavorite: boolean;
/**
* `true` if the more menu action should be shown for this file.
*/
showMore: boolean;
/**
* `true` if the delete action should be shown for this file.
*/
showDelete: boolean;
/**
* Set if the download action should be shown for this file.
*
@@ -71,6 +63,18 @@ export interface FileViewerFileAnnotation {
* Note: "bar" should only be set if {@link haveUser} is also true.
*/
showDownload: "bar" | "menu" | undefined;
/**
* `true` if the more menu action should be shown for this file.
*/
showMore: boolean;
/**
* `true` if the delete action should be shown for this file.
*/
showDelete: boolean;
/**
* `true` if the copy image action should be shown for this file.
*/
showCopyImage: boolean;
/**
* `true` if this is an image which can be edited, _and_ editing is
* possible, and the edit action should therefore be shown for this file.