From ac8e36a20b02c5ca4499283e9886cec8aa0a18a9 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Fri, 17 Dec 2021 00:21:36 +0400 Subject: [PATCH] Fix loading next items in empty media viewer --- src/components/appMediaViewerBase.ts | 13 ++++++++++--- src/components/avatar.ts | 2 +- src/helpers/avatarListLoader.ts | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/appMediaViewerBase.ts b/src/components/appMediaViewerBase.ts index f285e848..9a35ddd0 100644 --- a/src/components/appMediaViewerBase.ts +++ b/src/components/appMediaViewerBase.ts @@ -245,6 +245,11 @@ export default class AppMediaViewerBase< // * constructing html end + this.listLoader.onLoadedMore = () => { + this.buttons.prev.classList.toggle('hide', !this.listLoader.previous.length); + this.buttons.next.classList.toggle('hide', !this.listLoader.next.length); + }; + this.setNewMover(); } @@ -1173,9 +1178,11 @@ export default class AppMediaViewerBase< } */ } - /* if(this.nextTargets.length < 10 && this.loadMore) { - this.loadMore(); - } */ + if(this.listLoader.next.length < 10) { + setTimeout(() => { + this.listLoader.load(true); + }, 0); + } //if(prevTarget && (!prevTarget.parentElement || !this.isElementVisible(this.targetContainer, prevTarget))) prevTarget = null; //if(nextTarget && (!nextTarget.parentElement || !this.isElementVisible(this.targetContainer, nextTarget))) nextTarget = null; diff --git a/src/components/avatar.ts b/src/components/avatar.ts index 1ae73511..2bf55a31 100644 --- a/src/components/avatar.ts +++ b/src/components/avatar.ts @@ -101,7 +101,7 @@ export async function openAvatarViewer( } if(photo) { - if(!isObject(message)) { + if(!isObject(message) && message) { photo = appPhotosManager.getPhoto(message); } diff --git a/src/helpers/avatarListLoader.ts b/src/helpers/avatarListLoader.ts index af7da474..14b0e010 100644 --- a/src/helpers/avatarListLoader.ts +++ b/src/helpers/avatarListLoader.ts @@ -17,7 +17,7 @@ export default class AvatarListLoader loadMore: (anchor, older, loadCount) => { if(this.peerId.isAnyChat() || !older) return Promise.resolve({count: 0, items: []}); // ! это значит, что открыло аватар чата, но следующих фотографий нет. - const maxId = anchor?.photoId; + const maxId = anchor?.photoId || this.current?.photoId; return appPhotosManager.getUserPhotos(this.peerId, maxId, loadCount).then(value => { const items = value.photos.map(photoId => { return {element: null as HTMLElement, photoId} as any;