diff --git a/komga-webui/src/components/HorizontalScroller.vue b/komga-webui/src/components/HorizontalScroller.vue index 0cddacb55..2137cc9e6 100644 --- a/komga-webui/src/components/HorizontalScroller.vue +++ b/komga-webui/src/components/HorizontalScroller.vue @@ -22,7 +22,10 @@ @scroll="computeScrollability" v-resize="computeScrollability" > - +
+ + +
@@ -44,20 +47,35 @@ export default Vue.extend({ adjustment: 100, } }, + props: { + tick: { + type: Number, + default: 0, + }, + }, mounted() { this.container = this.$refs[this.id] as HTMLElement this.computeScrollability() }, + watch: { + tick() { + setTimeout(this.computeScrollability, 200) + }, + }, methods: { computeScrollability() { - if (this.container !== undefined) { + if (this.container) { + let scrollPercent: number if (this.$vuetify.rtl) { this.canScrollBackward = Math.round(this.container.scrollLeft) < 0 this.canScrollForward = (Math.round(this.container.scrollLeft) - this.container.clientWidth) > -this.container.scrollWidth + scrollPercent = (Math.round(this.container.scrollLeft) - this.container.clientWidth) / -this.container.scrollWidth } else { this.canScrollBackward = Math.round(this.container.scrollLeft) > 0 this.canScrollForward = (Math.round(this.container.scrollLeft) + this.container.clientWidth) < this.container.scrollWidth + scrollPercent = (Math.round(this.container.scrollLeft) + this.container.clientWidth) / this.container.scrollWidth } + this.$emit('scroll-changed', scrollPercent) } }, doScroll(direction: string) { diff --git a/komga-webui/src/types/pageLoader.ts b/komga-webui/src/types/pageLoader.ts new file mode 100644 index 000000000..6e1077977 --- /dev/null +++ b/komga-webui/src/types/pageLoader.ts @@ -0,0 +1,43 @@ +export class PageLoader { + private readonly pageable: PageRequest + private readonly loader: (pageRequest: PageRequest) => Promise> + + private currentPage = undefined as unknown as Page + private loadedPages: number[] = [] + public readonly items: T[] = [] + + get page() { + return this.currentPage?.number || 0 + } + get hasNextPage() { + return !this.currentPage ? false : !this.currentPage.last + } + + constructor(pageable: PageRequest, loader: (pageRequest: PageRequest) => Promise>) { + this.pageable = pageable + this.loader = loader + } + + async loadNext(): Promise { + // load first page if nothing has been loaded yet + if (!this.currentPage) { + this.loadedPages.push(this.pageable.page || 0) + this.currentPage = await this.loader(this.pageable) + this.items.push(...this.currentPage.content) + return true + } + // if the last page has been loaded, do nothing + else if (this.currentPage.last) return false + else { + const nextPage = this.currentPage.number + 1 + if (!this.loadedPages.includes(nextPage)) { + this.loadedPages.push(nextPage) + const pageable = Object.assign({}, this.pageable, {page: nextPage}) + this.currentPage = await this.loader(pageable) + this.items.push(...this.currentPage.content) + return true + } + return false + } + } +} diff --git a/komga-webui/src/views/Dashboard.vue b/komga-webui/src/views/Dashboard.vue index 9e24865e4..89b5ad133 100644 --- a/komga-webui/src/views/Dashboard.vue +++ b/komga-webui/src/views/Dashboard.vue @@ -49,12 +49,17 @@ > - +