summaryrefslogtreecommitdiff
path: root/src/client/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/scripts')
-rw-r--r--src/client/scripts/paging.ts30
1 files changed, 16 insertions, 14 deletions
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;