mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 00:52:55 +00:00
feat: add favorites support
This commit is contained in:
committed by
Rainer Killinger
parent
293ed6ba5f
commit
e9452d6520
@@ -109,7 +109,8 @@ describe('DataDetailComponent', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should get a data item when component is accessed', async () => {
|
||||
it('should get a data item when the view is entered', () => {
|
||||
comp.ionViewWillEnter();
|
||||
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(
|
||||
sampleThing.uid,
|
||||
);
|
||||
|
||||
@@ -12,18 +12,20 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Component} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {Network} from '@ionic-native/network/ngx';
|
||||
import {IonRefresher} from '@ionic/angular';
|
||||
import {LangChangeEvent, TranslateService} from '@ngx-translate/core';
|
||||
import {
|
||||
SCLanguageCode,
|
||||
SCSaveableThing,
|
||||
SCThings,
|
||||
SCUuid,
|
||||
SCSaveableThing,
|
||||
} from '@openstapps/core';
|
||||
import {DataProvider, DataScope} from '../data.provider';
|
||||
import {FavoritesService} from '../../favorites/favorites.service';
|
||||
import {take} from 'rxjs/operators';
|
||||
|
||||
/**
|
||||
* A Component to display an SCThing detailed
|
||||
@@ -33,7 +35,7 @@ import {DataProvider, DataScope} from '../data.provider';
|
||||
styleUrls: ['data-detail.scss'],
|
||||
templateUrl: 'data-detail.html',
|
||||
})
|
||||
export class DataDetailComponent implements OnInit {
|
||||
export class DataDetailComponent {
|
||||
/**
|
||||
* The associated item
|
||||
*
|
||||
@@ -60,12 +62,14 @@ export class DataDetailComponent implements OnInit {
|
||||
* @param route the route the page was accessed from
|
||||
* @param dataProvider the data provider
|
||||
* @param network the network provider
|
||||
* @param translateService the translation service
|
||||
* @param favoritesService the favorites provider
|
||||
* @param translateService he translate provider
|
||||
*/
|
||||
constructor(
|
||||
private readonly route: ActivatedRoute,
|
||||
private readonly dataProvider: DataProvider,
|
||||
private readonly network: Network,
|
||||
private readonly favoritesService: FavoritesService,
|
||||
translateService: TranslateService,
|
||||
) {
|
||||
this.language = translateService.currentLang as SCLanguageCode;
|
||||
@@ -99,8 +103,20 @@ export class DataDetailComponent implements OnInit {
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
ngOnInit() {
|
||||
void this.getItem(this.route.snapshot.paramMap.get('uid') ?? '');
|
||||
async ionViewWillEnter() {
|
||||
const uid = this.route.snapshot.paramMap.get('uid') || '';
|
||||
await this.getItem(uid ?? '');
|
||||
// fallback to the saved item (from favorites)
|
||||
if (this.item === null) {
|
||||
this.favoritesService
|
||||
.get(uid)
|
||||
.pipe(take(1))
|
||||
.subscribe(item => {
|
||||
if (typeof item !== undefined) {
|
||||
this.item = item;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
<ion-menu-button></ion-menu-button>
|
||||
</ion-buttons>
|
||||
<ion-title>{{ 'data.detail.TITLE' | translate }}</ion-title>
|
||||
<ion-buttons slot="primary">
|
||||
<stapps-favorite-button
|
||||
*ngIf="item"
|
||||
[item]="item"
|
||||
></stapps-favorite-button>
|
||||
</ion-buttons>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content class="ion-no-padding">
|
||||
|
||||
Reference in New Issue
Block a user