This commit is contained in:
Manav Rathi
2025-03-05 14:01:46 +05:30
parent b4a853acc5
commit e12a9aa800
2 changed files with 52 additions and 54 deletions

View File

@@ -41,6 +41,8 @@ import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import DeleteIcon from "@mui/icons-material/Delete"; import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit"; import EditIcon from "@mui/icons-material/Edit";
import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined"; import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import FullscreenExitOutlinedIcon from "@mui/icons-material/FullscreenExitOutlined";
import FullscreenOutlinedIcon from "@mui/icons-material/FullscreenOutlined";
import { Button, Menu, MenuItem, styled, Typography } from "@mui/material"; import { Button, Menu, MenuItem, styled, Typography } from "@mui/material";
import { t } from "i18next"; import { t } from "i18next";
import React, { import React, {
@@ -88,10 +90,6 @@ export interface FileViewerFileAnnotation {
* Note: "bar" should only be set if {@link haveUser} is also true. * Note: "bar" should only be set if {@link haveUser} is also true.
*/ */
showDownload: "bar" | "menu" | undefined; 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. * `true` if the delete action should be shown for this file.
*/ */
@@ -308,6 +306,7 @@ const FileViewer: React.FC<FileViewerProps> = ({
const [moreMenuAnchorEl, setMoreMenuAnchorEl] = const [moreMenuAnchorEl, setMoreMenuAnchorEl] =
useState<HTMLElement | null>(null); useState<HTMLElement | null>(null);
const [openImageEditor, setOpenImageEditor] = useState(false); const [openImageEditor, setOpenImageEditor] = useState(false);
const [isFullscreen, setIsFullscreen] = useState(false);
const { show: showConfirmDelete, props: confirmDeleteVisibilityProps } = const { show: showConfirmDelete, props: confirmDeleteVisibilityProps } =
useModalVisibility(); useModalVisibility();
@@ -517,18 +516,11 @@ const FileViewer: React.FC<FileViewerProps> = ({
} }
})(); })();
const showMore =
showDownload == "menu" ||
showDelete ||
showCopyImage ||
showEditImage;
return { return {
fileID, fileID,
isOwnFile, isOwnFile,
showFavorite, showFavorite,
showDownload, showDownload,
showMore,
showDelete, showDelete,
showCopyImage, showCopyImage,
showEditImage, showEditImage,
@@ -602,6 +594,18 @@ const FileViewer: React.FC<FileViewerProps> = ({
], ],
); );
const updateFullscreenStatus = useCallback(() => {
setIsFullscreen(!!document.fullscreenElement);
}, []);
const toggleFullscreen = useCallback(() => {
void (
document.fullscreenElement
? document.exitFullscreen()
: document.body.requestFullscreen()
).then(updateFullscreenStatus);
}, [updateFullscreenStatus]);
// Initial value of delegate. // Initial value of delegate.
if (!delegateRef.current) { if (!delegateRef.current) {
delegateRef.current = { getFiles, isFavorite, toggleFavorite }; delegateRef.current = { getFiles, isFavorite, toggleFavorite };
@@ -667,6 +671,8 @@ const FileViewer: React.FC<FileViewerProps> = ({
psRef.current!.refreshCurrentSlideContent(); psRef.current!.refreshCurrentSlideContent();
}, []); }, []);
useEffect(updateFullscreenStatus, [updateFullscreenStatus]);
log.debug(() => ["viewer", { action: "render", psRef: psRef.current }]); log.debug(() => ["viewer", { action: "render", psRef: psRef.current }]);
return ( return (
@@ -731,11 +737,19 @@ const FileViewer: React.FC<FileViewerProps> = ({
<EditIcon /> <EditIcon />
</MoreMenuItem> </MoreMenuItem>
)} )}
<MoreMenuItem onClick={handleToggleFullscreen}> <MoreMenuItem onClick={toggleFullscreen}>
<MoreMenuItemTitle> <MoreMenuItemTitle>
{/*TODO */ pt("Full screen")} {
/*TODO */ isFullscreen
? pt("Exit full screen")
: pt("Go full screen")
}
</MoreMenuItemTitle> </MoreMenuItemTitle>
<EditIcon /> {isFullscreen ? (
<FullscreenExitOutlinedIcon />
) : (
<FullscreenOutlinedIcon />
)}
</MoreMenuItem> </MoreMenuItem>
</MoreMenu> </MoreMenu>
{/* TODO(PS): Fix imports */} {/* TODO(PS): Fix imports */}
@@ -774,7 +788,7 @@ const MoreMenu = styled(Menu)`
`; `;
const MoreMenuItem = styled(MenuItem)` const MoreMenuItem = styled(MenuItem)`
min-width: 190px; min-width: 210px;
/* MUI MenuItem default implementation has a minHeight of "48px" below the /* MUI MenuItem default implementation has a minHeight of "48px" below the
"sm" breakpoint, and auto after it. We always want the same height, so "sm" breakpoint, and auto after it. We always want the same height, so
@@ -838,11 +852,3 @@ const createImagePNGBlob = async (imageURL: string) =>
image.onerror = reject; image.onerror = reject;
image.src = imageURL; image.src = imageURL;
}); });
/**
* Toggle full screen mode.
*/
const toggleFullscreen = () =>
document.fullscreenElement
? document.exitFullscreen()
: document.body.requestFullscreen();

View File

@@ -618,7 +618,6 @@ export class FileViewerPhotoSwipe {
onClick: () => onViewInfo(currentAnnotatedFile()), onClick: () => onViewInfo(currentAnnotatedFile()),
}); });
if (haveUser) {
pswp.ui.registerElement({ pswp.ui.registerElement({
name: "more", name: "more",
// TODO(PS): // TODO(PS):
@@ -629,12 +628,6 @@ export class FileViewerPhotoSwipe {
onInit: (buttonElement) => { onInit: (buttonElement) => {
buttonElement.setAttribute("id", moreButtonID); buttonElement.setAttribute("id", moreButtonID);
buttonElement.setAttribute("aria-haspopup", "true"); buttonElement.setAttribute("aria-haspopup", "true");
pswp.on("change", () =>
showIf(
buttonElement,
!!currentFileAnnotation().showMore,
),
);
}, },
onClick: (e) => { onClick: (e) => {
const buttonElement = e.target; const buttonElement = e.target;
@@ -648,7 +641,6 @@ export class FileViewerPhotoSwipe {
); );
}, },
}); });
}
pswp.ui.registerElement({ pswp.ui.registerElement({
name: "caption", name: "caption",