Skip to content

armgit / ente

Public Imported from GitHub
0

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

The dimensions are necessary

Manav Rathid4ddc0f91995
diff --git a/web/packages/new/photos/components/FileViewerPhotoSwipe.ts b/web/packages/new/photos/components/FileViewerPhotoSwipe.ts
index 8f0218f3ad..8569a07f2f 100644
--- a/web/packages/new/photos/components/FileViewerPhotoSwipe.ts
+++ b/web/packages/new/photos/components/FileViewerPhotoSwipe.ts
@@ -202,22 +202,21 @@ export class FileViewerPhotoSwipe {
pswp.addFilter("itemData", (_, index) => {
const file = files[index];
+ // We might not have anything to show immediately, though in most
+ // cases a cached renderable thumbnail URL will be available
+ // shortly.
+ //
+ // Meanwhile,
+ //
+ // 1. Return empty slide data; PhotoSwipe will not show anything in
+ // the image area but will otherwise render UI controls properly.
+ //
+ // 2. Insert empty data so that we don't enqueue multiple updates.
+
let itemData: SlideData | undefined;
if (file) {
itemData = this.itemDataByFileID.get(file.id);
if (!itemData) {
- // We don't have anything to show immediately, though in
- // most cases a cached renderable thumbnail URL will be
- // available shortly.
- //
- // Meanwhile,
- //
- // 1. Return empty slide data; PhotoSwipe will not show
- // anything in the image area but will otherwise render
- // the surrounding UI properly.
- //
- // 2. Insert empty data so that we don't enqueue multiple
- // updates.
itemData = {};
this.itemDataByFileID.set(file.id, itemData);
this.enqueueUpdates(index, file);
@@ -351,11 +350,18 @@ export class FileViewerPhotoSwipe {
};
const thumbnailURL = await downloadManager.renderableThumbnailURL(file);
- // We don't have the dimensions of the thumbnail. We could try to deduce
- // something from the file's aspect ratio etc, but that's not needed:
- // PhotoSwipe already correctly (for our purposes) handles just a source
- // URL being present.
- update({ src: thumbnailURL });
+ const thumbnailURLWithDimensions = await new Promise((resolve) => {
+ let image = new Image();
+ image.onload = () => {
+ resolve({
+ src: thumbnailURL,
+ width: image.naturalWidth,
+ height: image.naturalHeight,
+ });
+ };
+ image.src = thumbnailURL;
+ });
+ update(thumbnailURLWithDimensions);
switch (file.metadata.fileType) {
case FileType.image: {