From 491751f4fc7d7779f793b3773c6e6673c306b5ef Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Tue, 4 Feb 2020 14:51:48 +0100 Subject: [PATCH] Frontend: Fixed infinite scroll and reload Signed-off-by: Michael Mayer --- frontend/src/pages/album/photos.vue | 142 ++++++++++++++++++++++++---- frontend/src/pages/albums.vue | 28 ++++-- frontend/src/pages/labels.vue | 27 ++++-- frontend/src/pages/photos.vue | 28 ++++-- internal/api/album.go | 4 + 5 files changed, 182 insertions(+), 47 deletions(-) diff --git a/frontend/src/pages/album/photos.vue b/frontend/src/pages/album/photos.vue index 5fa755041..2877e7966 100644 --- a/frontend/src/pages/album/photos.vue +++ b/frontend/src/pages/album/photos.vue @@ -3,7 +3,7 @@ :infinite-scroll-distance="10" :infinite-scroll-listen-for-event="'scrollRefresh'"> + :refresh="refresh"> @@ -43,6 +43,7 @@ diff --git a/frontend/src/pages/albums.vue b/frontend/src/pages/albums.vue index 89d6a58ff..cf85f8eee 100644 --- a/frontend/src/pages/albums.vue +++ b/frontend/src/pages/albums.vue @@ -201,16 +201,24 @@ Object.assign(params, this.lastFilter); - Album.search(params).then(response => { - this.page++; - this.offset += this.pageSize; + if (this.staticFilter) { + Object.assign(params, this.staticFilter); + } + Album.search(params).then(response => { this.results = this.dirty ? response.models : this.results.concat(response.models); this.scrollDisabled = (response.models.length < count); if (this.scrollDisabled) { - this.$notify.info(this.$gettext("All ") + this.results.length + this.$gettext(" albums loaded")); + this.offset = offset; + + if(this.results.length > 1) { + this.$notify.info(this.$gettext("All ") + this.results.length + this.$gettext(" albums loaded")); + } + } else { + this.offset = offset + count; + this.page++; } }).catch(() => { this.scrollDisabled = false; @@ -298,12 +306,12 @@ }); }, refresh() { - this.lastFilter = {}; - const pageSize = this.pageSize; - this.pageSize = this.offset + pageSize; - this.search(); - this.offset = this.pageSize; - this.pageSize = pageSize; + if(this.loading) return; + this.loading = true; + this.page = 0; + this.dirty = true; + this.scrollDisabled = false; + this.loadMore(); }, create() { let name = DateTime.local().toFormat("LLLL yyyy"); diff --git a/frontend/src/pages/labels.vue b/frontend/src/pages/labels.vue index dbbf9f274..77dd8b93b 100644 --- a/frontend/src/pages/labels.vue +++ b/frontend/src/pages/labels.vue @@ -230,16 +230,23 @@ Object.assign(params, this.lastFilter); - Label.search(params).then(response => { - this.page++; - this.offset += this.pageSize; + if (this.staticFilter) { + Object.assign(params, this.staticFilter); + } + Label.search(params).then(response => { this.results = this.dirty ? response.models : this.results.concat(response.models); this.scrollDisabled = (response.models.length < count); if (this.scrollDisabled) { - this.$notify.info(this.$gettext('All ') + this.results.length + this.$gettext(' labels loaded')); + this.offset = offset; + if(this.results.length > 1) { + this.$notify.info(this.$gettext('All ') + this.results.length + this.$gettext(' labels loaded')); + } + } else { + this.offset = offset + count; + this.page++; } }).catch(() => { this.scrollDisabled = false; @@ -283,12 +290,12 @@ return params; }, refresh() { - this.lastFilter = {}; - const pageSize = this.pageSize; - this.pageSize = this.offset + pageSize; - this.search(); - this.offset = this.pageSize; - this.pageSize = pageSize; + if(this.loading) return; + this.loading = true; + this.page = 0; + this.dirty = true; + this.scrollDisabled = false; + this.loadMore(); }, search() { this.scrollDisabled = true; diff --git a/frontend/src/pages/photos.vue b/frontend/src/pages/photos.vue index 5e462d89f..f7a010829 100644 --- a/frontend/src/pages/photos.vue +++ b/frontend/src/pages/photos.vue @@ -157,16 +157,24 @@ Object.assign(params, this.lastFilter); - Photo.search(params).then(response => { - this.page++; - this.offset += this.pageSize; + if (this.staticFilter) { + Object.assign(params, this.staticFilter); + } + Photo.search(params).then(response => { this.results = this.dirty ? response.models : this.results.concat(response.models); this.scrollDisabled = (response.models.length < count); if (this.scrollDisabled) { - this.$notify.info(this.$gettext('All ') + this.results.length + this.$gettext(' photos loaded')); + this.offset = offset; + + if(this.results.length > 1) { + this.$notify.info(this.$gettext('All ') + this.results.length + this.$gettext(' photos loaded')); + } + } else { + this.offset = offset + count; + this.page++; } }).catch(() => { this.scrollDisabled = false; @@ -210,12 +218,12 @@ return params; }, refresh() { - this.lastFilter = {}; - const pageSize = this.pageSize; - this.pageSize = this.offset + pageSize; - this.search(); - this.offset = this.pageSize; - this.pageSize = pageSize; + if(this.loading) return; + this.loading = true; + this.page = 0; + this.dirty = true; + this.scrollDisabled = false; + this.loadMore(); }, search() { this.scrollDisabled = true; diff --git a/internal/api/album.go b/internal/api/album.go index 81f4f131a..d3a99eb62 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -281,6 +281,8 @@ func AddPhotosToAlbum(router *gin.RouterGroup, conf *config.Config) { event.Success(fmt.Sprintf("%d photos added to %s", len(added), a.AlbumName)) } + PublishAlbumEvent(EntityUpdated, a.AlbumUUID, c, q) + c.JSON(http.StatusOK, gin.H{"message": "photos added to album", "album": a, "added": added}) }) } @@ -320,6 +322,8 @@ func RemovePhotosFromAlbum(router *gin.RouterGroup, conf *config.Config) { event.Success(fmt.Sprintf("photos removed from %s", a.AlbumName)) + PublishAlbumEvent(EntityUpdated, a.AlbumUUID, c, q) + c.JSON(http.StatusOK, gin.H{"message": "photos removed from album", "album": a, "photos": f.Photos}) }) }