This commit is contained in:
Manav Rathi
2025-03-17 18:46:30 +05:30
parent 4c1bdcf3d0
commit d58af3f88d
5 changed files with 21 additions and 49 deletions

View File

@@ -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]);

View File

@@ -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 });
}
},
[],

View File

@@ -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>;
/**

View File

@@ -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);
// Not using stateByUpdatingFilteredFiles since it does not depend
// on pendingVisibilityUpdates.
return { ...state, pendingVisibilityUpdates };
}
// Skipping a call to stateByUpdatingFilteredFiles since it
// currently doesn't depend on 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,

View File

@@ -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.
*/