Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Prevent Escape from closing single-file public viewer

Anand Baburajanae2dbd2c1519
diff --git a/web/apps/photos/src/components/PublicAlbumSingleFileViewer.tsx b/web/apps/photos/src/components/PublicAlbumSingleFileViewer.tsx
index ae8b0f64b4..899580c75e 100644
--- a/web/apps/photos/src/components/PublicAlbumSingleFileViewer.tsx
+++ b/web/apps/photos/src/components/PublicAlbumSingleFileViewer.tsx
@@ -338,6 +338,7 @@ export const PublicAlbumSingleFileViewer: React.FC<
onClose={handleViewerClose}
files={[file]}
initialIndex={0}
+ disableEscapeClose
disableDownload={!enableDownload}
onDownload={enableDownload ? handleDownload : undefined}
onVisualFeedback={onVisualFeedback}
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index dc208938a9..af543417a5 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -367,6 +367,10 @@ export type FileViewerProps = ModalVisibilityProps & {
* otherwise.
*/
shouldCloseOnBrowserBack?: boolean;
+ /**
+ * If `true`, disables closing the viewer with the Escape key.
+ */
+ disableEscapeClose?: boolean;
/**
* The decrypted collection key (base64 encoded) for encrypting reactions.
* Required when viewing a public album (no logged in user).
@@ -441,6 +445,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
activeCollectionID,
publicAlbumsCredentials,
shouldCloseOnBrowserBack: shouldCloseOnBrowserBackOverride,
+ disableEscapeClose = false,
collectionKey,
onJoinAlbum,
enableComment = true,
@@ -2497,6 +2502,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
showSocialButtons,
enableComment,
showFullscreenButton,
+ disableEscapeClose,
delegate: delegateRef.current!,
onClose: () => {
if (psRef.current) handleClose();
@@ -2538,6 +2544,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
initialIndex,
disableDownload,
showFullscreenButton,
+ disableEscapeClose,
haveUser,
isPublicAlbum,
handleClose,
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 449512aa56..3cda405e47 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -121,7 +121,7 @@ export interface FileViewerPhotoSwipeDelegate {
type FileViewerPhotoSwipeOptions = Pick<
FileViewerProps,
- "initialIndex" | "showFullscreenButton"
+ "initialIndex" | "showFullscreenButton" | "disableEscapeClose"
> & {
/**
* `true` if we're running in the context of a logged in user, and so
@@ -255,6 +255,7 @@ export class FileViewerPhotoSwipe {
showSocialButtons,
enableComment,
showFullscreenButton,
+ disableEscapeClose,
delegate,
onClose,
onAnnotate,
@@ -288,6 +289,9 @@ export class FileViewerPhotoSwipe {
// auto hide based on mouse activity, but that would not have any
// effect on touch devices)
bgClickAction: "toggle-controls",
+ // In single-file public viewer mode we keep Escape for nested UI
+ // interactions while preventing accidental viewer closure.
+ escKey: !disableEscapeClose,
// At least on macOS, manual zooming with the trackpad is very
// cumbersome (possibly because of the small multiplier in the
// PhotoSwipe source, but I'm not sure). The other option to do a