feat: refresh on pull for news module

This commit is contained in:
Jovan Krunić
2021-01-21 21:21:29 +01:00
parent 22cd0af1bf
commit 1f3d9ad5f0
2 changed files with 33 additions and 5 deletions

View File

@@ -13,6 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component} from '@angular/core';
import {IonRefresher} from '@ionic/angular';
import {SCMessage} from '@openstapps/core';
import {NewsProvider} from '../news.provider';
/**
@@ -26,16 +27,38 @@ export class NewsPageComponent {
/**
* News (messages) to show
*/
news: SCMessage[];
news: SCMessage[] = [];
constructor(private newsProvider: NewsProvider) {
}
/**
* Initialize the local variables on component initialization
* Fetch news from the backend
*/
async ngOnInit() {
async fetchNews() {
/* tslint:disable:no-magic-numbers */
this.news = await this.newsProvider.getList(30, true);
}
/**
* Initialize the local variables on component initialization
*/
ngOnInit() {
void this.fetchNews();
}
/**
* Updates the shown list
*
* @param refresher Refresher component that triggers the update
*/
async refresh(refresher: IonRefresher) {
try {
await this.fetchNews();
} catch (e) {
this.news = [];
} finally {
await refresher.complete();
}
}
}