π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
edit
Manav Rathiacaf1939e71a
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex ad7247a3ea..ff360ceba8 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -211,33 +211,6 @@ const FileViewer: React.FC<FileViewerProps> = ({// If `true`, then we need to trigger a sync with remote when we close.const [, setNeedsSync] = useState(false);- const handleClose = useCallback(() => {- setNeedsSync((needSync) => {- if (needSync) onTriggerSyncWithRemote?.();- return false;- });- setOpenFileInfo(false);- setOpenImageEditor(false);- onClose();- }, [onTriggerSyncWithRemote, onClose]);-- 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;- const isEditableImage =- onSaveEditedImageCopy && canModify- ? fileIsEditableImage(file)- : undefined;- return { fileID, isOwnFile, showFavorite, isEditableImage };- },- [user, isInTrashSection, isInHiddenSection, onSaveEditedImageCopy],- );-const handleViewInfo = useCallback((annotatedFile: FileViewerAnnotatedFile) => {setActiveAnnotatedFile(annotatedFile);@@ -253,25 +226,6 @@ const FileViewer: React.FC<FileViewerProps> = ({const handleFileInfoClose = useCallback(() => setOpenFileInfo(false), []);- const handleScheduleUpdate = useCallback(() => setNeedsSync(true), []);-- const handleSelectCollection = useCallback(- (collectionID: number) => {- onSelectCollection(collectionID);- handleClose();- },- [onSelectCollection, handleClose],- );-- const handleSelectPerson = useMemo(() => {- return onSelectPerson- ? (personID: string) => {- onSelectPerson(personID);- handleClose();- }- : undefined;- }, [onSelectPerson, handleClose]);-const handleMore = useCallback((annotatedFile: FileViewerAnnotatedFile,@@ -292,40 +246,91 @@ const FileViewer: React.FC<FileViewerProps> = ({const handleEditImage = useMemo(() => {return onSaveEditedImageCopy- ? (annotatedFile: FileViewerAnnotatedFile) => {- setActiveAnnotatedFile(annotatedFile);+ ? () => {+ handleMoreMenuClose();setOpenImageEditor(true);}: undefined;- }, [onSaveEditedImageCopy]);+ }, [onSaveEditedImageCopy, handleMoreMenuClose]);const handleImageEditorClose = useCallback(() => setOpenImageEditor(false),[],);+ const handleClose = useCallback(() => {+ setNeedsSync((needSync) => {+ if (needSync) onTriggerSyncWithRemote?.();+ return false;+ });+ handleFileInfoClose();+ handleImageEditorClose();+ handleMoreMenuClose();+ onClose();+ }, [+ onTriggerSyncWithRemote,+ handleFileInfoClose,+ handleImageEditorClose,+ handleMoreMenuClose,+ onClose,+ ]);+const handleSaveEditedCopy = useCallback((editedFile: File, collection: Collection, enteFile: EnteFile) => {onSaveEditedImageCopy(editedFile, collection, enteFile);- handleImageEditorClose();handleClose();},- [onSaveEditedImageCopy, handleImageEditorClose, handleClose],+ [onSaveEditedImageCopy, handleClose],+ );++ 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;+ const isEditableImage =+ handleEditImage && canModify+ ? fileIsEditableImage(file)+ : undefined;+ return { fileID, isOwnFile, showFavorite, isEditableImage };+ },+ [user, isInTrashSection, isInHiddenSection, handleEditImage],+ );++ const handleScheduleUpdate = useCallback(() => setNeedsSync(true), []);++ const handleSelectCollection = useCallback(+ (collectionID: number) => {+ onSelectCollection(collectionID);+ handleClose();+ },+ [onSelectCollection, handleClose],);+ const handleSelectPerson = useMemo(() => {+ return onSelectPerson+ ? (personID: string) => {+ onSelectPerson(personID);+ handleClose();+ }+ : undefined;+ }, [onSelectPerson, handleClose]);+const haveUser = !!user;- const showModifyActions = haveUser;const getFiles = useCallback(() => files, [files]);const isFavorite = useCallback(({ file }: FileViewerAnnotatedFile) => {- if (!showModifyActions || !favoriteFileIDs || !onToggleFavorite) {+ if (!haveUser || !favoriteFileIDs || !onToggleFavorite) {return undefined;}return favoriteFileIDs.has(file.id);},- [showModifyActions, favoriteFileIDs, onToggleFavorite],+ [haveUser, favoriteFileIDs, onToggleFavorite],);const toggleFavorite = useCallback(@@ -355,13 +360,12 @@ const FileViewer: React.FC<FileViewerProps> = ({const pswp = new FileViewerPhotoSwipe({initialIndex,disableDownload,- showModifyActions,+ haveUser,delegate: delegateRef.current!,onClose: handleClose,onAnnotate: handleAnnotate,onViewInfo: handleViewInfo,onMore: handleMore,- onEditImage: handleEditImage,});psRef.current = pswp;@@ -378,12 +382,11 @@ const FileViewer: React.FC<FileViewerProps> = ({user,initialIndex,disableDownload,- showModifyActions,+ haveUser,handleClose,handleAnnotate,handleViewInfo,handleMore,- handleEditImage,]);const handleRefreshPhotoswipe = useCallback(() => {@@ -419,7 +422,9 @@ const FileViewer: React.FC<FileViewerProps> = ({}}>{activeAnnotatedFile?.annotation.isEditableImage && (- <MenuItem>{/*TODO */ pt("Edit image")}</MenuItem>+ <MenuItem onClick={handleEditImage}>+ {/*TODO */ pt("Edit image")}+ </MenuItem>)}</Menu><ImageEditorOverlaydiff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.tsindex 8c564a55ff..d84458c268 100644--- a/web/packages/gallery/components/viewer/photoswipe.ts+++ b/web/packages/gallery/components/viewer/photoswipe.ts@@ -54,10 +54,8 @@ export interface FileViewerFileAnnotation {*/showFavorite: boolean;/**- * `true` if this is an image which can be edited.- *- * The edit button is shown when this is true. See also the- * {@link onEditImage} option for {@link FileViewerPhotoSwipe} constructor.+ * `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.*/isEditableImage: boolean;}@@ -104,17 +102,18 @@ type FileViewerPhotoSwipeOptions = Pick<"initialIndex" | "disableDownload"> & {/**- * `true` if various actions that modify the file should be shown.+ * `true` if we're running in the context of a logged in user, and so+ * various actions that modify the file should be shown.*- * This is the static variant of various per file annotations. If this is- * not `true`, then various actions like favorite, delete etc are never- * shown. If this is `true`, then their visibility depends on the- * corresponding annotation.+ * This is the static variant of various per file annotations that control+ * various modifications. If this is not `true`, then various actions like+ * favorite, delete etc are never shown. If this is `true`, then their+ * visibility depends on the corresponding annotation.** For example, the favorite action is shown only if both this and the* {@link showFavorite} file annotation are true.*/- showModifyActions: boolean;+ haveUser: boolean;/*** Dynamic callbacks.*@@ -145,16 +144,6 @@ type FileViewerPhotoSwipeOptions = Pick<annotatedFile: FileViewerAnnotatedFile,buttonElement: HTMLElement,) => void;- /**- * Called when the user activates the edit action on an image.- *- * If this callback is not provided, then the edit action is never shown. If- * this callback is provided (and {@link showModifyActions} is `true`), then- * the visibility of the edit action is determined by the- * {@link isEditableImage} property of the {@link FileViewerFileAnnotation}- * for the file.- */- onEditImage?: (annotatedFile: FileViewerAnnotatedFile) => void;};/**@@ -248,13 +237,12 @@ export class FileViewerPhotoSwipe {constructor({initialIndex,disableDownload,- showModifyActions,+ haveUser,delegate,onClose,onAnnotate,onViewInfo,onMore,- onEditImage,}: FileViewerPhotoSwipeOptions) {this.opts = { disableDownload };this.lastActivityDate = new Date();@@ -522,7 +510,7 @@ export class FileViewerPhotoSwipe {},});- if (showModifyActions) {+ if (haveUser) {const toggleFavorite = async (buttonElement: HTMLButtonElement,) => {@@ -602,7 +590,7 @@ export class FileViewerPhotoSwipe {onClick: () => onViewInfo(currentAnnotatedFile()),});- if (showModifyActions && onEditImage) {+ if (haveUser) {pswp.ui.registerElement({name: "more",// TODO(PS):