Skip to content

armgit / ente

Public Imported from GitHub
0

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

Mention file rename

Manav Rathi82063ce97248
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 8f69c207a4..0e2327d97c 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -770,8 +770,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
performKeyAction,
]);
- // Update the active annotated file, if needed, on updates to files or
- // favoriteFileIDs.
+ // Update the active annotated file, if needed, on updates to files.
//
// If the active annotated file is no longer being shown, move to the next
// slide if possible, or close the viewer otherwise.
@@ -780,45 +779,60 @@ export const FileViewer: React.FC<FileViewerProps> = ({
// Do nothing if we're not showing a file (we might not be open).
if (!af) return af;
- if (files.length) {
- const updatedFile = files.find(({ id }) => id == af?.file.id);
- if (updatedFile) {
- // Modify the active annotated file if we found a file with
- // the same ID in the (possibly) updated files array.
- //
- // This is not correct in its full generality, but it works
- // fine in the specific cases we would need to handle (and
- // we want to avoid refreshing the entire UI unnecessarily
- // lest the user lose their zoom/pan etc):
- //
- // - In case of delete or toggling archived that caused the
- // file is no longer part of the list that is shown, we'll
- // not get to this code branch.
- //
- // - In case of toggling archive otherwise, just updating
- // the file attribute is enough, the UI state is derived
- // from it; none of the other attributes of the annotated
- // file currently depend on the archive status change.
- af = { ...af, file: updatedFile };
- } else {
- // The file we were displaying is no longer part of the list
- // of files that should be displayed. Refresh the slides,
- // adjusting the indexes as necessary.
- //
- // A special case is when we might've been the last slide,
- // in which case we need to go back one slide first. To
- // determine this, also pass the expected count of files to
- // our PhotoSwipe wrapper.
- psRef.current?.refreshCurrentSlideContentAfterRemove(
- files.length,
- );
- }
- } else {
+ if (!files.length) {
// If there are no more files left, close the viewer.
handleClose();
+ return af;
+ }
+
+ const updatedFile = files.find(({ id }) => id == af.file.id);
+ if (!updatedFile) {
+ // The file we were displaying is no longer part of the list of
+ // files that should be displayed. Refresh the slides, adjusting
+ // the indexes as necessary.
+ //
+ // A special case is when we might've been the last slide, in
+ // which case we need to go back one slide first. To determine
+ // if this is needed, we also pass the expected count of files
+ // to our PhotoSwipe wrapper.
+ psRef.current?.refreshCurrentSlideContentAfterRemove(
+ files.length,
+ );
+ return af;
}
- return af;
+ // There was an update to the files array, something that might've
+ // also potentially modified the file we're currently viewing, and
+ // we also found a (possibly) file with the same ID in the
+ // (possibly) updated files array.
+ //
+ // > Possibly because these are not deep equality comparisons, and
+ // > we might get here when the array's identity has changed but not
+ // > necessarily its contents.
+ //
+ // We could always refresh the current slide when we get here,
+ // however we want to avoid refreshing the entire UI unnecessarily
+ // lest the user lose their zoom/pan etc.
+ //
+ // So instead we only modify the file property of the active
+ // annotated file.
+ //
+ // This is not correct in its full generality, but it works fine in
+ // the specific cases we need to handle where the file gets updated
+ // from within the file viewer:
+ //
+ // - In case of deleting a file, or toggling its archived status to
+ // something that that caused the file to no longer part of the
+ // list that is shown, we'll not get to this code branch.
+ //
+ // - In case of toggling archive otherwise, just updating the file
+ // attribute is enough, the UI state is derived from it; none of
+ // the other attributes of the annotated file currently depend on
+ // the archive status change.
+ //
+ // - Similar reasoning applies to updates to the file's fileName in
+ // the file info panel.
+ return { ...af, file: updatedFile };
});
}, [handleClose, files]);