Update timeline.vue

This commit is contained in:
Daniel Supernault 2019-01-11 13:40:15 -07:00
parent 0d6a8e3486
commit 888ccc9dce
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 32 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View file

@ -92,10 +92,15 @@
</form> </form>
</div> </div>
</div> </div>
<!--
<infinite-loading @infinite="infiniteTimeline"> <infinite-loading @infinite="infiniteTimeline">
<div slot="no-more" class="font-weight-bold text-light">No more posts to load</div> <div slot="no-more" class="font-weight-bold text-light">No more posts to load</div>
<div slot="no-results" class="font-weight-bold text-light">No posts found</div> <div slot="no-results" class="font-weight-bold text-light">No posts found</div>
</infinite-loading> </infinite-loading>
-->
<div class="pagination d-none">
<p class="btn btn-outline-secondary font-weight-bold btn-block" v-on:click="loadMore">Load more posts</p>
</div>
</div> </div>
<div class="col-md-4 col-lg-4 pt-2 my-3 order-1 order-md-2"> <div class="col-md-4 col-lg-4 pt-2 my-3 order-1 order-md-2">
@ -265,7 +270,6 @@
let localTimeline = '/api/v1/timelines/public?page=1'; let localTimeline = '/api/v1/timelines/public?page=1';
let apiUrl = this.scope == '/' ? homeTimeline : localTimeline; let apiUrl = this.scope == '/' ? homeTimeline : localTimeline;
axios.get(apiUrl).then(res => { axios.get(apiUrl).then(res => {
$('.timeline .loader').addClass('d-none');
let data = res.data; let data = res.data;
this.feed.push(...data); this.feed.push(...data);
let ids = data.map(status => status.id); let ids = data.map(status => status.id);
@ -273,6 +277,7 @@
if(this.page == 1) { if(this.page == 1) {
this.max_id = Math.max(...ids); this.max_id = Math.max(...ids);
} }
$('.timeline .pagination').removeClass('d-none');
this.loading = false; this.loading = false;
}).catch(err => { }).catch(err => {
}); });
@ -304,6 +309,30 @@
}); });
}, },
loadMore() {
let homeTimeline = '/api/v1/timelines/home';
let localTimeline = '/api/v1/timelines/public';
let apiUrl = this.scope == '/' ? homeTimeline : localTimeline;
axios.get(apiUrl, {
params: {
page: this.page,
},
}).then(res => {
if (res.data.length && this.loading == false) {
let data = res.data;
this.feed.push(...data);
let ids = data.map(status => status.id);
this.min_id = Math.min(...ids);
if(this.page == 1) {
this.max_id = Math.max(...ids);
}
this.page += 1;
this.loading = false;
} else {
}
});
},
fetchNotifications() { fetchNotifications() {
axios.get('/api/v1/notifications') axios.get('/api/v1/notifications')
.then(res => { .then(res => {