From e2af372baa925ae3f593ada7dd6826c22db38994 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Fri, 14 Oct 2022 10:43:50 -0700 Subject: [PATCH 1/3] Move debouncing only to PDF render to fix completion. --- .../assets/src/views/PdfRendererIndex.vue | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index 1bbfe1edb3a..b69ceb284f2 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -166,6 +166,13 @@ return this.totalPages * 30; }, /* eslint-enable kolibri/vue-no-unused-properties */ + debouncedShowVisiblePages() { + // So as not to share debounced functions between instances of the same component + // and also to allow access to the cancel method of the debounced function + // best practice seems to be to do it as a computed property and not a method: + // https://github.com/vuejs/vue/issues/2870#issuecomment-219096773 + return debounce(this.showVisiblePages, renderDebounceTime); + }, }, watch: { recycleListIsMounted(newVal) { @@ -301,7 +308,7 @@ this.savedVisitedPages = visited; }, // handle the recycle list update event - handleUpdate: debounce(function(start, end) { + handleUpdate(start, end) { // check that it is mounted if (!this.$refs.recycleList || !this.$refs.recycleList.$el) { return; @@ -325,19 +332,26 @@ // TODO: there is a miscalculation that causes a wrong position change on scale this.savePosition(this.calculatePosition()); - // determine how many pages user has viewed/visited; fix edge case of 2 pages - let currentPage = - this.totalPages === 2 ? 2 : parseInt(this.currentLocation * this.totalPages) + 1; + // determine how many pages user has viewed/visited + const currentPage = parseInt(this.currentLocation * this.totalPages) + 1; + // If the user has already scrolled all the way to the end and is still not scrolled + // to the final page, set the final page as viewed as well. + if (currentPage === this.totalPages - 1 && this.scrolledToEnd()) { + this.storeVisitedPage(currentPage + 1); + } this.storeVisitedPage(currentPage); this.updateProgress(); this.updateContentState(); } + this.debouncedShowVisiblePages(start, end); + }, + showVisiblePages(start, end) { const startIndex = Math.floor(start) + 1; const endIndex = Math.ceil(end) + 1; for (let i = startIndex; i <= endIndex; i++) { this.showPage(i); } - }, renderDebounceTime), + }, zoomIn() { this.setScale(Math.min(scaleIncrement * 20, this.scale + scaleIncrement)); }, @@ -350,6 +364,12 @@ calculatePosition() { return this.$refs.recycleList.$el.scrollTop / this.$refs.recycleList.$el.scrollHeight; }, + scrolledToEnd() { + return ( + this.$refs.recycleList.$el.scrollTop + this.$refs.recycleList.$el.clientHeight === + this.$refs.recycleList.$el.scrollHeight + ); + }, savePosition(val) { this.currentLocation = val; }, From 055115c0ce52d7d84aeea4e1bd21f2470a389246 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Fri, 14 Oct 2022 10:46:10 -0700 Subject: [PATCH 2/3] Remove autohiding of control panel. --- .../pdf_viewer/assets/src/views/PdfRendererIndex.vue | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index b69ceb284f2..349bf981a07 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -17,7 +17,6 @@