Commit 8bdcbde9 authored by Martin Santangelo's avatar Martin Santangelo

(feat) infinite scroll feed service

1 merge request!290[Sprint/KiltedKoala] (feat) infinite scroll feed service
......@@ -44,11 +44,26 @@ export default class FeedsService {
*/
feed = [];
/**
* @var {string}
*/
pagingToken: string = '';
/**
* @var {boolean}
*/
endReached = false;
/**
* Get entities from the current page
*/
async getEntities() {
const end = this.limit + this.offset;
if (end > this.feed.length && !this.endReached) {
await this.fetch();
}
const feedPage = this.feed.slice(this.offset, this.limit + this.offset);
return await entitiesService.getFromFeed(feedPage, this, this.asActivities);
}
......@@ -150,9 +165,14 @@ export default class FeedsService {
*/
async fetch() {
abort(this);
const response = await apiService.get(this.endpoint, {...this.params, ...{ limit: 150, as_activities: this.asActivities ? 1 : 0 }}, this);
const response = await apiService.get(this.endpoint, {...this.params, ...{ limit: 150, as_activities: this.asActivities ? 1 : 0, from_timestamp: this.pagingToken }}, this);
this.feed = response.entities;
if (response.entities.length) {
this.feed = this.feed.concat(response.entities);
this.pagingToken = response['load-next'];
} else {
this.endReached = true;
}
// save without wait
feedsStorage.save(this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment