Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix(gallery):added-ref-callback-for-closing-FileViewer-from-gallery

Aswin Asokcdd34fd100d5
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index 945c9c6105..4f8c33a7e4 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -13,7 +13,7 @@ import { fileCreationTime, fileFileName } from "ente-media/file-metadata";
import { moveToTrash } from "ente-new/photos/services/collection";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
import { t } from "i18next";
-import { useCallback, useMemo, useState } from "react";
+import { useCallback, useEffect, useMemo, useState } from "react";
import AutoSizer from "react-virtualized-auto-sizer";
import { uploadManager } from "services/upload-manager";
import {
@@ -57,6 +57,11 @@ export type FileListWithViewerProps = {
file: EnteFile,
sourceCollectionSummaryID?: number,
) => void;
+ /**
+ * Provides a callback that closes the file viewer, allowing parents to
+ * dismiss it programmatically.
+ */
+ onRegisterCloseFileViewer?: (close?: () => void) => void;
} & Pick<
FileListProps,
| "mode"
@@ -127,6 +132,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
onSelectCollection,
onSelectPerson,
onAddFileToCollection,
+ onRegisterCloseFileViewer,
}) => {
const [openFileViewer, setOpenFileViewer] = useState(false);
const [currentIndex, setCurrentIndex] = useState(0);
@@ -154,6 +160,12 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
setOpenFileViewer(false);
}, [onSetOpenFileViewer]);
+ useEffect(() => {
+ if (!onRegisterCloseFileViewer) return;
+ onRegisterCloseFileViewer(handleCloseFileViewer);
+ return () => onRegisterCloseFileViewer(undefined);
+ }, [onRegisterCloseFileViewer, handleCloseFileViewer]);
+
const handleTriggerRemotePull = useCallback(
() => void onRemotePull(),
[onRemotePull],
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index f66616a712..616b960548 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -47,8 +47,7 @@ import { type UploadTypeSelectorIntent } from "ente-gallery/components/Upload";
import { useSaveGroups } from "ente-gallery/components/utils/save-groups";
import { type Collection } from "ente-media/collection";
import { type EnteFile } from "ente-media/file";
-import { fileFileName } from "ente-media/file-metadata";
-import { type ItemVisibility } from "ente-media/file-metadata";
+import { fileFileName, type ItemVisibility } from "ente-media/file-metadata";
import {
CollectionSelector,
type CollectionSelectorAttributes,
@@ -180,6 +179,7 @@ const Page: React.FC = () => {
const pendingSingleFileAdd = useRef<
{ file: EnteFile; sourceCollectionSummaryID?: number } | undefined
>(undefined);
+ const closeFileViewerRef = useRef<(() => void) | undefined>(undefined);
/**
* A queue to serialize calls to {@link remoteFilesPull}.
*/
@@ -742,6 +742,17 @@ const Page: React.FC = () => {
[pendingSingleFileAdd.current.file],
pendingSingleFileAdd.current.sourceCollectionSummaryID,
);
+
+ await remotePull({ silent: true });
+ //Show custom toast with file name and navigation
+ setAddToAlbumProgress({
+ open: true,
+ phase: "done",
+ albumId: collection.id,
+ fileName: fileFileName(
+ pendingSingleFileAdd.current.file,
+ ),
+ });
}
setPostCreateAlbumOp((postCreateAlbumOp) => {
@@ -756,7 +767,7 @@ const Page: React.FC = () => {
pendingSingleFileAdd.current = undefined;
}
},
- [createOnSelectForCollectionOp],
+ [createOnSelectForCollectionOp, remotePull],
);
const createFileOpHandler = (op: FileOp) => () => {
@@ -1005,6 +1016,10 @@ const Page: React.FC = () => {
[],
);
+ const registerCloseFileViewer = useCallback((closer?: () => void) => {
+ closeFileViewerRef.current = closer;
+ }, []);
+
const handleCloseCollectionSelector = useCallback(
() => setOpenCollectionSelector(false),
[],
@@ -1302,6 +1317,7 @@ const Page: React.FC = () => {
onSelectCollection={handleSelectCollection}
onSelectPerson={handleSelectPerson}
onAddFileToCollection={handleAddSingleFileToCollection}
+ onRegisterCloseFileViewer={registerCloseFileViewer}
/>
)}
<Export {...exportVisibilityProps} {...{ collectionNameByID }} />
@@ -1331,6 +1347,7 @@ const Page: React.FC = () => {
phase={addToAlbumProgress.phase}
fileName={addToAlbumProgress.fileName}
onArrowClick={() => {
+ closeFileViewerRef.current?.();
if (addToAlbumProgress.albumId !== undefined) {
handleSelectCollection(addToAlbumProgress.albumId);
}