mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: lazy load all news
This commit is contained in:
@@ -24,20 +24,38 @@ import {NewsProvider} from '../news.provider';
|
||||
templateUrl: 'news-page.html',
|
||||
})
|
||||
export class NewsPageComponent {
|
||||
/**
|
||||
* Thing counter to start query the next page from
|
||||
*/
|
||||
from = 0;
|
||||
/**
|
||||
* Page size of queries
|
||||
*/
|
||||
pageSize = 10;
|
||||
/**
|
||||
* News (messages) to show
|
||||
*/
|
||||
news: SCMessage[] = [];
|
||||
|
||||
constructor(private newsProvider: NewsProvider) {
|
||||
}
|
||||
constructor(private newsProvider: NewsProvider) {}
|
||||
|
||||
/**
|
||||
* Fetch news from the backend
|
||||
*/
|
||||
async fetchNews() {
|
||||
/* tslint:disable:no-magic-numbers */
|
||||
this.news = await this.newsProvider.getList(30);
|
||||
this.news = await this.newsProvider.getList(this.pageSize, this.from);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads more news
|
||||
*
|
||||
* @param event Signal from the infinite scroll to load more data
|
||||
*/
|
||||
// tslint:disable-next-line:no-any
|
||||
async loadMore(event: any): Promise<void> {
|
||||
this.from += this.pageSize;
|
||||
this.news = this.news.concat(await this.newsProvider.getList(this.pageSize, this.from));
|
||||
event.target.complete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,6 +72,7 @@ export class NewsPageComponent {
|
||||
*/
|
||||
async refresh(refresher: IonRefresher) {
|
||||
try {
|
||||
this.from = 0;
|
||||
await this.fetchNews();
|
||||
} catch (e) {
|
||||
this.news = [];
|
||||
|
||||
Reference in New Issue
Block a user