Skip to content

armgit / ente

Public Imported from GitHub
0

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

Make fullscreen button more visible in embed viewer

Manav Rathi5f45c4189cca
diff --git a/web/apps/embed/src/components/EmbedFileListWithViewer.tsx b/web/apps/embed/src/components/EmbedFileListWithViewer.tsx
index 366d7c78e0..40208ce57d 100644
--- a/web/apps/embed/src/components/EmbedFileListWithViewer.tsx
+++ b/web/apps/embed/src/components/EmbedFileListWithViewer.tsx
@@ -129,6 +129,7 @@ export const EmbedFileListWithViewer: React.FC<
initialIndex={currentIndex}
files={files}
disableDownload={true}
+ showFullscreenButton={true}
onTriggerRemotePull={handleTriggerRemotePull}
onVisualFeedback={() => {
console.log("Visual feedback requested");
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index d7da4f2555..10fbf06e77 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -160,6 +160,11 @@ export type FileViewerProps = ModalVisibilityProps & {
* If true then the viewer does not show controls for downloading the file.
*/
disableDownload?: boolean;
+ /**
+ * If true then the fullscreen button is shown as a primary action button
+ * in the toolbar instead of being hidden in the more menu.
+ */
+ showFullscreenButton?: boolean;
/**
* `true` when we are viewing files in an album that the user does not own.
*/
@@ -290,6 +295,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
files,
initialIndex,
disableDownload,
+ showFullscreenButton,
isInIncomingSharedCollection,
isInTrashSection,
isInHiddenSection,
@@ -813,6 +819,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const pswp = new FileViewerPhotoSwipe({
initialIndex,
haveUser,
+ showFullscreenButton,
delegate: delegateRef.current!,
onClose: () => {
if (psRef.current) handleClose();
@@ -843,6 +850,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
user,
initialIndex,
disableDownload,
+ showFullscreenButton,
haveUser,
handleClose,
handleAnnotate,
diff --git a/web/packages/gallery/components/viewer/icons.tsx b/web/packages/gallery/components/viewer/icons.tsx
index c0f9bc81e1..253817cfdd 100644
--- a/web/packages/gallery/components/viewer/icons.tsx
+++ b/web/packages/gallery/components/viewer/icons.tsx
@@ -37,9 +37,13 @@ const paths = {
info: '<path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8" transform="translate(1, 4.5) scale(0.95)"',
// "@mui/icons-material/MoreHoriz"
more: '<path d="M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2" transform="translate(0, 4.5)"',
+ // "@mui/icons-material/FullscreenOutlined"
+ fullscreen: '<path d="M7 14H5v5h5v-2H7zm-2-4h2V7h3V5H5zm12 7h-3v2h5v-5h-2zM14 5v2h3v3h2V5z" transform="translate(0, 4.5)"',
+ // "@mui/icons-material/FullscreenExitOutlined"
+ "fullscreen-exit": '<path d="M5 16h3v3h2v-5H5zm3-8H5v2h5V5H8zm6 11h2v-3h3v-2h-5zm2-11V5h-2v5h5V8z" transform="translate(0, 4.5)"',
};
-type IconKeys = Exclude<keyof typeof paths, "favorite-fill">;
+type IconKeys = Exclude<keyof typeof paths, "favorite-fill" | "fullscreen-exit">;
/**
* Return an object that can be passed verbatim to the "html" option expected by
@@ -62,6 +66,8 @@ export const createPSRegisterElementIconHTML = (name: IconKeys) => ({
inner:
name == "favorite"
? favoriteInner()
+ : name == "fullscreen"
+ ? fullscreenInner()
: `${paths[name]} id="pswp__icn-${name}" />`,
outlineID: `pswp__icn-${name}`,
});
@@ -70,6 +76,10 @@ export const createPSRegisterElementIconHTML = (name: IconKeys) => ({
const favoriteInner = () =>
`${paths.favorite} id="pswp__icn-favorite" />${paths["favorite-fill"]} id="pswp__icn-favorite-fill" />`;
+// Fullscreen is also a special case since it has two states.
+const fullscreenInner = () =>
+ `${paths.fullscreen} id="pswp__icn-fullscreen" />${paths["fullscreen-exit"]} id="pswp__icn-fullscreen-exit" />`;
+
/**
* The path of "@mui/icons-material/Settings" as as string.
*
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index bd4151d68a..86274f9201 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -90,7 +90,7 @@ export interface FileViewerPhotoSwipeDelegate {
) => void;
}
-type FileViewerPhotoSwipeOptions = Pick<FileViewerProps, "initialIndex"> & {
+type FileViewerPhotoSwipeOptions = Pick<FileViewerProps, "initialIndex" | "showFullscreenButton"> & {
/**
* `true` if we're running in the context of a logged in user, and so
* various actions that modify the file should be shown.
@@ -189,6 +189,7 @@ export class FileViewerPhotoSwipe {
constructor({
initialIndex,
haveUser,
+ showFullscreenButton,
delegate,
onClose,
onAnnotate,
@@ -1243,6 +1244,38 @@ export class FileViewerPhotoSwipe {
},
});
+ // Add fullscreen button as a primary action for embed app
+ if (showFullscreenButton) {
+ ui.registerElement({
+ name: "fullscreen",
+ title: t("toggle_fullscreen"),
+ order: 18,
+ isButton: true,
+ html: createPSRegisterElementIconHTML("fullscreen"),
+ onInit: (buttonElement, pswp) => {
+ const updateIcon = () => {
+ const isFullscreen = !!document.fullscreenElement;
+ const fullscreenIcon = buttonElement.querySelector("#pswp__icn-fullscreen");
+ const exitIcon = buttonElement.querySelector("#pswp__icn-fullscreen-exit");
+ if (fullscreenIcon && exitIcon) {
+ showIf(fullscreenIcon as HTMLElement, !isFullscreen);
+ showIf(exitIcon as HTMLElement, isFullscreen);
+ }
+ };
+
+ // Update icon on fullscreen changes
+ document.addEventListener("fullscreenchange", updateIcon);
+ pswp.on("destroy", () => {
+ document.removeEventListener("fullscreenchange", updateIcon);
+ });
+
+ // Initialize icon state
+ updateIcon();
+ },
+ onClick: handleToggleFullscreen,
+ });
+ }
+
ui.registerElement({
name: "media-controls",
// Arbitrary order towards the end.