diff --git a/komga-webui/src/types/pageLoader.ts b/komga-webui/src/types/pageLoader.ts index 6e1077977..9f0dd3809 100644 --- a/komga-webui/src/types/pageLoader.ts +++ b/komga-webui/src/types/pageLoader.ts @@ -4,26 +4,42 @@ export class PageLoader { private currentPage = undefined as unknown as Page private loadedPages: number[] = [] + private _tick = 0 public readonly items: T[] = [] - get page() { - return this.currentPage?.number || 0 - } get hasNextPage() { return !this.currentPage ? false : !this.currentPage.last } + get tick() { + return this._tick + } + constructor(pageable: PageRequest, loader: (pageRequest: PageRequest) => Promise>) { this.pageable = pageable this.loader = loader } + async reload() { + if (!this.currentPage) return this.loadNext() + + const pageable = Object.assign({}, this.pageable, + { + size: (this.currentPage.number + 1) * (this.pageable.size || 20), + page: 0, + }) + const page = await this.loader(pageable) + this.items.splice(0, this.items.length, ...page.content) + this._tick++ + } + 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) + this._tick++ return true } // if the last page has been loaded, do nothing @@ -35,6 +51,7 @@ export class PageLoader { const pageable = Object.assign({}, this.pageable, {page: nextPage}) this.currentPage = await this.loader(pageable) this.items.push(...this.currentPage.content) + this._tick++ return true } return false diff --git a/komga-webui/src/views/Dashboard.vue b/komga-webui/src/views/Dashboard.vue index 7d1e2d266..d30aaa26d 100644 --- a/komga-webui/src/views/Dashboard.vue +++ b/komga-webui/src/views/Dashboard.vue @@ -52,7 +52,7 @@