Update lightbox with images generated while it is open

This removes the need to close and re-open the lightbox to view images
that were completed while it was open.
This commit is contained in:
Torbjörn Lönnemark
2024-03-23 16:31:07 +01:00
parent 2b35fab29e
commit 865094ca5b
2 changed files with 12 additions and 0 deletions
+10
View File
@@ -107,6 +107,16 @@ export class Lightbox {
this.img.src = img;
this.img.style.opacity = 1;
}
async updateWithNewImage(img, feedDirection) {
// No-op if lightbox is not open
if (this.el.style.display === "none" || this.el.style.opacity === "0") return;
// Ensure currently shown image does not change
const [method, shift] = feedDirection === "newest first" ? ["unshift", 1] : ["push", 0];
this.images[method](img);
await this.update(shift);
}
}
export const lightbox = new Lightbox();