This commit is contained in:
こぴなたみぽ 2017-12-21 11:08:17 +09:00
parent 42cfe26f19
commit 169142cec3
2 changed files with 11 additions and 12 deletions

View File

@ -41,7 +41,8 @@
this.isLoading = true; this.isLoading = true;
this.isEmpty = false; this.isEmpty = false;
this.moreLoading = false; this.moreLoading = false;
this.page = 0; this.limit = 30;
this.offset = 0;
this.on('mount', () => { this.on('mount', () => {
document.addEventListener('keydown', this.onDocumentKeydown); document.addEventListener('keydown', this.onDocumentKeydown);
@ -72,16 +73,16 @@
this.more = () => { this.more = () => {
if (this.moreLoading || this.isLoading || this.timeline.posts.length == 0) return; if (this.moreLoading || this.isLoading || this.timeline.posts.length == 0) return;
this.offset += this.limit;
this.update({ this.update({
moreLoading: true moreLoading: true
}); });
this.api('posts/search', { return this.api('posts/search', Object.assign({}, parse(this.query), {
query: this.query, limit: this.limit,
page: this.page + 1 offset: this.offset
}).then(posts => { }).then(posts => {
this.update({ this.update({
moreLoading: false, moreLoading: false
page: page + 1
}); });
this.refs.timeline.prependPosts(posts); this.refs.timeline.prependPosts(posts);
}); });

View File

@ -19,11 +19,10 @@
this.mixin('api'); this.mixin('api');
this.max = 30; this.limit = 30;
this.offset = 0; this.offset = 0;
this.query = this.opts.query; this.query = this.opts.query;
this.withMedia = this.opts.withMedia;
this.init = new Promise((res, rej) => { this.init = new Promise((res, rej) => {
this.api('posts/search', parse(this.query)).then(posts => { this.api('posts/search', parse(this.query)).then(posts => {
@ -33,10 +32,9 @@
}); });
this.more = () => { this.more = () => {
this.offset += this.max; this.offset += this.limit;
return this.api('posts/search', { return this.api('posts/search', Object.assign({}, parse(this.query), {
query: this.query, limit: this.limit,
max: this.max,
offset: this.offset offset: this.offset
}); });
}; };