Skip to content

armgit / ente

Public Imported from GitHub
0

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

Upd

Manav Rathid58af3f88dfa
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index 83fd21d52f..d4a206c614 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -174,11 +174,8 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
const handleDelete = useMemo(() => {
return onMarkTempDeleted
- ? async (file: EnteFile) => {
- await moveToTrash([file]);
- // See: [Note: File viewer update and dispatch]
- onMarkTempDeleted?.([file]);
- }
+ ? (file: EnteFile) =>
+ moveToTrash([file]).then(() => onMarkTempDeleted?.([file]))
: undefined;
}, [onMarkTempDeleted]);
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index e781c9d445..66a8f654fd 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -804,35 +804,19 @@ const Page: React.FC = () => {
const handleFileViewerFileVisibilityUpdate = useCallback(
async (file: EnteFile, visibility: ItemVisibility) => {
const fileID = file.id;
- dispatch({
- type: "markPendingVisibilityUpdate",
- fileID,
- mark: true,
- });
-
+ dispatch({ type: "addPendingVisibilityUpdate", fileID });
try {
const privateMagicMetadata =
await updateRemotePrivateMagicMetadata(file, {
visibility,
});
- // TODO(AR): Trigger a "lite" sync?
-
- // The file viewer listens for the next update to files, so keep
- // this as the first operation on the happy path that can
- // trigger an update of files.
- //
- // See: [Note: File viewer update and dispatch]
dispatch({
type: "unsyncedPrivateMagicMetadataUpdate",
fileID,
privateMagicMetadata,
});
} finally {
- dispatch({
- type: "markPendingVisibilityUpdate",
- fileID,
- mark: false,
- });
+ dispatch({ type: "removePendingVisibilityUpdate", fileID });
}
},
[],
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index c65bde365c..a01d3db249 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -236,16 +236,12 @@ export type FileViewerProps = ModalVisibilityProps & {
* Called when the given {@link file} should be downloaded.
*
* If this is not provided then the download action will not be shown.
- *
- * See also: [Note: File viewer update and dispatch]
*/
onDownload?: (file: EnteFile) => void;
/**
* Called when the given {@link file} should be deleted.
*
* If this is not provided then the delete action will not be shown.
- *
- * See also: [Note: File viewer update and dispatch]
*/
onDelete?: (file: EnteFile) => Promise<void>;
/**
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index cf4ec89dfa..6a4bf0732d 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -434,12 +434,8 @@ export type GalleryAction =
| { type: "clearTempDeleted" }
| { type: "markTempHidden"; files: EnteFile[] }
| { type: "clearTempHidden" }
- | {
- type: "markPendingVisibilityUpdate";
- fileID: number;
- // Passing `true` adds an entry, and `false` clears any existing one.
- mark: boolean;
- }
+ | { type: "addPendingVisibilityUpdate"; fileID: number }
+ | { type: "removePendingVisibilityUpdate"; fileID: number }
| {
type: "unsyncedPrivateMagicMetadataUpdate";
fileID: number;
@@ -879,17 +875,21 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
tempHiddenFileIDs: new Set(),
});
- case "markPendingVisibilityUpdate": {
+ case "addPendingVisibilityUpdate": {
const pendingVisibilityUpdates = new Set(
state.pendingVisibilityUpdates,
);
- if (action.mark) {
- pendingVisibilityUpdates.add(action.fileID);
- } else {
- pendingVisibilityUpdates.delete(action.fileID);
- }
- // Skipping a call to stateByUpdatingFilteredFiles since it
- // currently doesn't depend on pendingVisibilityUpdates.
+ pendingVisibilityUpdates.add(action.fileID);
+ // Not using stateByUpdatingFilteredFiles since it does not depend
+ // on pendingVisibilityUpdates.
+ return { ...state, pendingVisibilityUpdates };
+ }
+
+ case "removePendingVisibilityUpdate": {
+ const pendingVisibilityUpdates = new Set(
+ state.pendingVisibilityUpdates,
+ );
+ pendingVisibilityUpdates.delete(action.fileID);
return { ...state, pendingVisibilityUpdates };
}
@@ -897,17 +897,14 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
const unsyncedPrivateMagicMetadataUpdates = new Map(
state.unsyncedPrivateMagicMetadataUpdates,
);
-
unsyncedPrivateMagicMetadataUpdates.set(
action.fileID,
action.privateMagicMetadata,
);
-
const files = deriveNormalOrHiddenFiles(
state.lastSyncedFiles,
unsyncedPrivateMagicMetadataUpdates,
);
-
return stateByUpdatingFilteredFiles({
...stateForUpdatedFiles(state, files),
unsyncedPrivateMagicMetadataUpdates,
diff --git a/web/packages/new/photos/services/sync.ts b/web/packages/new/photos/services/sync.ts
index e78ac03237..450f7ba1f6 100644
--- a/web/packages/new/photos/services/sync.ts
+++ b/web/packages/new/photos/services/sync.ts
@@ -32,16 +32,14 @@ import { splitByPredicate } from "@/utils/array";
*
* In some other cases, where we know that only specific collection and/or file
* state needs to be synced, step 2 ({@link syncCollectionAndFiles}) is
- * performed independently. Examples of such cases are:
+ * performed independently. The only example of such a cases currently is:
*
* - After deduping files.
- * - After performing a file operation (e.g. delete, toggle favorite, toggle
- * archive) within the file viewer.
*
* The full sync is performed in the following cases:
*
- * - On the gallery page load for web and desktop
- * - Every 5 minutes thereafter (while the gallery page remains in front).
+ * - On the gallery page load (for both web and desktop).
+ * - Every 5 minutes thereafter (while the user is on the gallery page).
* - Each time the desktop app gains focus.
* - When the file viewer is closed after performing some operation.
*/