This commit is contained in:
Manav Rathi
2025-02-27 17:07:58 +05:30
parent 0bfd355233
commit e87d596b4c
3 changed files with 108 additions and 46 deletions

View File

@@ -76,6 +76,13 @@ export type FileViewerProps = ModalVisibilityProps & {
* If true then the viewer does not show controls for downloading the file.
*/
disableDownload?: boolean;
/**
* File IDs of all the files that the user has marked as a favorite.
*
* If this is not provided then the favorite toggle button will not be shown
* in the file actions.
*/
favoriteFileIDs?: Set<number>;
/**
* Called when there was some update performed within the file viewer that
* necessitates us to sync with remote again to fetch the latest updates.
@@ -119,6 +126,7 @@ const FileViewer: React.FC<FileViewerProps> = ({
files,
initialIndex,
disableDownload,
favoriteFileIDs,
fileCollectionIDs,
allCollectionsNameByID,
onSelectCollection,
@@ -162,14 +170,27 @@ const FileViewer: React.FC<FileViewerProps> = ({
const handleAnnotate = useCallback(
(file: EnteFile) => {
log.debug(() => ["viewer", { action: "annotate", file }]);
const fileID = file.id;
const isOwnFile = file.ownerID == user?.id;
const isEditableImage = fileIsEditableImage(file);
return { fileID, isOwnFile, isEditableImage };
const isFavorite = favoriteFileIDs?.has(file.id);
const isEditableImage = onSaveEditedImageCopy
? fileIsEditableImage(file)
: undefined;
return { fileID, isOwnFile, isFavorite, isEditableImage };
},
[user],
[user, favoriteFileIDs, onSaveEditedImageCopy],
);
const handleToggleFavorite = useMemo(() => {
return favoriteFileIDs
? (annotatedFile: FileViewerAnnotatedFile) => {
setActiveAnnotatedFile(annotatedFile);
console.log("handleToggleFavorite", annotatedFile);
}
: undefined;
}, [favoriteFileIDs]);
const handleViewInfo = useCallback(
(annotatedFile: FileViewerAnnotatedFile) => {
setActiveAnnotatedFile(annotatedFile);
@@ -208,7 +229,6 @@ const FileViewer: React.FC<FileViewerProps> = ({
return onSaveEditedImageCopy
? (annotatedFile: FileViewerAnnotatedFile) => {
setActiveAnnotatedFile(annotatedFile);
setActiveFileExif(undefined);
setOpenImageEditor(true);
}
: undefined;
@@ -242,6 +262,7 @@ const FileViewer: React.FC<FileViewerProps> = ({
disableDownload,
onClose: handleClose,
onAnnotate: handleAnnotate,
onToggleFavorite: handleToggleFavorite,
onViewInfo: handleViewInfo,
onEditImage: handleEditImage,
});