mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 09:32:41 +00:00
feat: refresh on pull for news module
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user