Skip to content

armgit / ente

Public Imported from GitHub
0

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

diversion: pswp doesn't reset isOpen

Manav Rathif3d9595953d2
diff --git a/web/apps/photos/src/components/PhotoFrame.tsx b/web/apps/photos/src/components/PhotoFrame.tsx
index 62a70d5a22..61300576c3 100644
--- a/web/apps/photos/src/components/PhotoFrame.tsx
+++ b/web/apps/photos/src/components/PhotoFrame.tsx
@@ -1,4 +1,3 @@
-import { useModalVisibility } from "@/base/components/utils/modal";
import log from "@/base/log";
import {
downloadManager,
@@ -160,8 +159,9 @@ const PhotoFrame = ({
const [isShiftKeyPressed, setIsShiftKeyPressed] = useState(false);
const router = useRouter();
- const { show: showPhotoSwipe, props: photoSwipeVisibilityProps } =
- useModalVisibility();
+ // const { show: showPhotoSwipe, props: photoSwipeVisibilityProps } =
+ // useModalVisibility();
+ const [open5, setOpen5] = useState(false);
const [displayFiles, setDisplayFiles] = useState<DisplayFile[] | undefined>(
undefined,
@@ -259,15 +259,20 @@ const PhotoFrame = ({
};
const handleClose = (needUpdate) => {
- setOpen(false);
- needUpdate && syncWithRemote();
- setIsPhotoSwipeOpen?.(false);
+ if (process.env.NEXT_PUBLIC_ENTE_WIP_PS5) {
+ setOpen5(false);
+ } else {
+ setOpen(false);
+ needUpdate && syncWithRemote();
+ setIsPhotoSwipeOpen?.(false);
+ }
};
const onThumbnailClick = (index: number) => () => {
setCurrentIndex(index);
if (process.env.NEXT_PUBLIC_ENTE_WIP_PS5) {
- showPhotoSwipe();
+ // showPhotoSwipe();
+ setOpen5(true);
} else {
setOpen(true);
setIsPhotoSwipeOpen?.(true);
@@ -513,8 +518,9 @@ const PhotoFrame = ({
<Container>
{process.env.NEXT_PUBLIC_ENTE_WIP_PS5 && (
<FileViewer
- {...photoSwipeVisibilityProps}
/* @ts-expect-error TODO(PS): test */
+ open={open5}
+ onClose={handleClose}
files={files}
index={currentIndex}
/>
diff --git a/web/packages/new/photos/components/FileViewer5.tsx b/web/packages/new/photos/components/FileViewer5.tsx
index 84b51da3cc..c121cee102 100644
--- a/web/packages/new/photos/components/FileViewer5.tsx
+++ b/web/packages/new/photos/components/FileViewer5.tsx
@@ -62,7 +62,12 @@ interface FileViewerProps {
*
* The documentation for PhotoSwipe is at https://photoswipe.com/.
*/
-const FileViewer: React.FC<FileViewerProps> = ({ open, files, index }) => {
+const FileViewer: React.FC<FileViewerProps> = ({
+ open,
+ onClose,
+ files,
+ index,
+}) => {
const pswpRef = useRef<PhotoSwipe | undefined>();
useEffect(() => {
@@ -86,6 +91,10 @@ const FileViewer: React.FC<FileViewerProps> = ({ open, files, index }) => {
height: 100,
};
});
+ pswp.on("close", () => {
+ console.log("pswp.on(close)")
+ onClose();
+ });
pswpRef.current = pswp;
return () => {
@@ -94,6 +103,8 @@ const FileViewer: React.FC<FileViewerProps> = ({ open, files, index }) => {
};
}, []);
+ console.log({ open, pswpIsOpen: pswpRef.current?.isOpen });
+
useEffect(() => {
const pswp = pswpRef.current!;
if (open) {
@@ -105,11 +116,16 @@ const FileViewer: React.FC<FileViewerProps> = ({ open, files, index }) => {
} else {
if (pswp.isOpen) {
// Closing PhotoSwipe removes it from the DOM.
+ //
+ // We get to this particular point if we're being closed
+ // externally.
pswp.close();
}
}
}, [open]);
+ const handleClose = () => {};
+
return (
<Container>
<Button>Test</Button>