[web] Handle deletion of last slide

This commit is contained in:
Manav Rathi
2025-03-07 19:40:11 +05:30
parent f29341ccb2
commit 2a70327153
2 changed files with 16 additions and 3 deletions

View File

@@ -423,7 +423,11 @@ export const FileViewer: React.FC<FileViewerProps> = ({
// Refreshing the current slide after the current file has gone
// will show the subsequent slide (since that would've now moved
// down to the current index).
psRef.current!.refreshCurrentSlideContent();
//
// However, 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!.refreshCurrentSlideContent(files.length);
} else {
// If there are no more files left, close the viewer.
handleClose();

View File

@@ -1046,9 +1046,18 @@ export class FileViewerPhotoSwipe {
/**
* Reload the current slide, asking the data source for its data afresh.
*
* @param expectedFileCount The count of files that we expect to show after
* the refresh. If provided, this is used to (circle) go back to the first
* slide when the slide which we were at previously is not available anymore
* (e.g. when deleting the last file in a sequence).
*/
refreshCurrentSlideContent() {
this.pswp.refreshSlideContent(this.pswp.currIndex);
refreshCurrentSlideContent(expectedFileCount?: number) {
if (expectedFileCount && this.pswp.currIndex >= expectedFileCount) {
this.pswp.goTo(0);
} else {
this.pswp.refreshSlideContent(this.pswp.currIndex);
}
}
}