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:
@@ -29,8 +29,9 @@ export class NewsProvider {
|
|||||||
* Get news messages
|
* Get news messages
|
||||||
*
|
*
|
||||||
* @param size How many messages/news to fetch
|
* @param size How many messages/news to fetch
|
||||||
|
* @param from From which (results) page to start
|
||||||
*/
|
*/
|
||||||
async getList(size: number): Promise<SCMessage[]> {
|
async getList(size: number, from: number): Promise<SCMessage[]> {
|
||||||
const result = await this.dataProvider.search({
|
const result = await this.dataProvider.search({
|
||||||
filter: {
|
filter: {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
@@ -47,6 +48,7 @@ export class NewsProvider {
|
|||||||
order: 'desc',
|
order: 'desc',
|
||||||
}],
|
}],
|
||||||
size: size,
|
size: size,
|
||||||
|
from: from,
|
||||||
});
|
});
|
||||||
|
|
||||||
return result.data as SCMessage[];
|
return result.data as SCMessage[];
|
||||||
|
|||||||
@@ -24,20 +24,38 @@ import {NewsProvider} from '../news.provider';
|
|||||||
templateUrl: 'news-page.html',
|
templateUrl: 'news-page.html',
|
||||||
})
|
})
|
||||||
export class NewsPageComponent {
|
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 (messages) to show
|
||||||
*/
|
*/
|
||||||
news: SCMessage[] = [];
|
news: SCMessage[] = [];
|
||||||
|
|
||||||
constructor(private newsProvider: NewsProvider) {
|
constructor(private newsProvider: NewsProvider) {}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch news from the backend
|
* Fetch news from the backend
|
||||||
*/
|
*/
|
||||||
async fetchNews() {
|
async fetchNews() {
|
||||||
/* tslint:disable:no-magic-numbers */
|
this.news = await this.newsProvider.getList(this.pageSize, this.from);
|
||||||
this.news = await this.newsProvider.getList(30);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
async refresh(refresher: IonRefresher) {
|
||||||
try {
|
try {
|
||||||
|
this.from = 0;
|
||||||
await this.fetchNews();
|
await this.fetchNews();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.news = [];
|
this.news = [];
|
||||||
|
|||||||
@@ -4,18 +4,15 @@
|
|||||||
<ion-back-button></ion-back-button>
|
<ion-back-button></ion-back-button>
|
||||||
<ion-menu-button></ion-menu-button>
|
<ion-menu-button></ion-menu-button>
|
||||||
</ion-buttons>
|
</ion-buttons>
|
||||||
<!--TODO: read this from the config (menu item title)-->
|
|
||||||
<ion-title>{{'news.title' | translate}}</ion-title>
|
<ion-title>{{'news.title' | translate}}</ion-title>
|
||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
</ion-header>
|
</ion-header>
|
||||||
|
|
||||||
<ion-content fullscreen>
|
<ion-content fullscreen>
|
||||||
<ion-refresher slot="fixed" (ionRefresh)="refresh($event.target)">
|
<ion-refresher slot="fixed" (ionRefresh)="refresh($event.target)">
|
||||||
<ion-refresher-content
|
<ion-refresher-content pullingIcon="chevron-down-outline" pullingText="{{'data.REFRESH_ACTION' | translate}}"
|
||||||
pullingIcon="chevron-down-outline"
|
|
||||||
pullingText="{{ 'data.REFRESH_ACTION' | translate }}"
|
|
||||||
refreshingText="{{'data.REFRESHING' | translate}}"
|
refreshingText="{{'data.REFRESHING' | translate}}"
|
||||||
>
|
refreshingSpinner="crescent">
|
||||||
</ion-refresher-content>
|
</ion-refresher-content>
|
||||||
</ion-refresher>
|
</ion-refresher>
|
||||||
<ion-grid>
|
<ion-grid>
|
||||||
@@ -30,4 +27,8 @@
|
|||||||
</ion-col>
|
</ion-col>
|
||||||
</ion-row>
|
</ion-row>
|
||||||
</ion-grid>
|
</ion-grid>
|
||||||
|
<ion-infinite-scroll id="infinite-scroll" threshold="20%" (ionInfinite)="loadMore($event)">
|
||||||
|
<ion-infinite-scroll-content loading-spinner="crescent">
|
||||||
|
</ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|||||||
Reference in New Issue
Block a user