This commit is contained in:
syuilo
2020-02-16 22:15:49 +09:00
parent bcd7d1f007
commit dc39caed1e
5 changed files with 100 additions and 27 deletions

View File

@ -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;