From dc39caed1e735e4ce580d6acfc31cf3a56ce28d5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 16 Feb 2020 22:15:49 +0900 Subject: Resolve #5942 --- src/client/scripts/paging.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/client/scripts') diff --git a/src/client/scripts/paging.ts b/src/client/scripts/paging.ts index 07eaf20ff3..64c744e45d 100644 --- a/src/client/scripts/paging.ts +++ b/src/client/scripts/paging.ts @@ -64,18 +64,18 @@ export default (opts) => ({ if (params && params.then) params = await params; const endpoint = typeof this.pagination.endpoint === 'function' ? this.pagination.endpoint() : this.pagination.endpoint; await this.$root.api(endpoint, { + ...params, limit: this.pagination.noPaging ? (this.pagination.limit || 10) : (this.pagination.limit || 10) + 1, - ...params - }).then(x => { - if (!this.pagination.noPaging && (x.length === (this.pagination.limit || 10) + 1)) { - x.pop(); - this.items = x; + }).then(items => { + if (!this.pagination.noPaging && (items.length === (this.pagination.limit || 10) + 1)) { + items.pop(); + this.items = this.pagination.reversed ? [...items].reverse() : items; this.more = true; } else { - this.items = x; + this.items = this.pagination.reversed ? [...items].reverse() : items; this.more = false; } - this.offset = x.length; + this.offset = items.length; this.inited = true; this.fetching = false; if (opts.after) opts.after(this, null); @@ -93,23 +93,25 @@ export default (opts) => ({ if (params && params.then) params = await params; const endpoint = typeof this.pagination.endpoint === 'function' ? this.pagination.endpoint() : this.pagination.endpoint; await this.$root.api(endpoint, { + ...params, limit: SECOND_FETCH_LIMIT + 1, ...(this.pagination.offsetMode ? { offset: this.offset, + } : this.pagination.reversed ? { + sinceId: this.items[0].id, } : { untilId: this.items[this.items.length - 1].id, }), - ...params - }).then(x => { - if (x.length === SECOND_FETCH_LIMIT + 1) { - x.pop(); - this.items = this.items.concat(x); + }).then(items => { + if (items.length === SECOND_FETCH_LIMIT + 1) { + items.pop(); + this.items = this.pagination.reversed ? [...items].reverse().concat(this.items) : this.items.concat(items); this.more = true; } else { - this.items = this.items.concat(x); + this.items = this.pagination.reversed ? [...items].reverse().concat(this.items) : this.items.concat(items); this.more = false; } - this.offset += x.length; + this.offset += items.length; this.moreFetching = false; }, e => { this.moreFetching = false; -- cgit v1.2.3-freya