From d1a49dae323867aff6aff85c96a52199b9b7154c Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Thu, 3 Mar 2022 15:12:19 +0100 Subject: [PATCH] ajout favoris sur pages categories --- .../pages/resto-page/resto-page.component.ts | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/app/pages/resto-page/resto-page.component.ts b/src/app/pages/resto-page/resto-page.component.ts index 5f4d94f..caf6e22 100644 --- a/src/app/pages/resto-page/resto-page.component.ts +++ b/src/app/pages/resto-page/resto-page.component.ts @@ -20,26 +20,27 @@ export class RestoPageComponent implements OnInit { private tokenService : TokenService) { this.listRestaurants = []; this.restaurantPref = []; + this.beforeRoute = this.apiBackService.routeParam; } ngOnInit(): void { - this.beforeRoute = this.apiBackService.routeParam; + this.restauLiked(); - // arrivée sur la restau-page depuis filtres ou home(catégories) : appel a une méthode différente du service - if(this.apiBackService.routeParam === "filtres"){ - this.listRestaurants = this.apiBackService.restoFilter; + // // arrivée sur la restau-page depuis filtres ou home(catégories) : appel a une méthode différente du service + // if(this.apiBackService.routeParam === "filtres"){ + // this.listRestaurants = this.apiBackService.restoFilter; - }else if(this.apiBackService.routeParam === "categories"){ - this.apiBackService.restoByCat.subscribe((restaurants: any[]) => { - this.listRestaurants = restaurants; - }); - }else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés + // }else if(this.apiBackService.routeParam === "categories"){ + // this.apiBackService.restoByCat.subscribe((restaurants: any[]) => { + // this.listRestaurants = restaurants; + // }); + // }else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés - this.restauLiked(); + // this.restauLiked(); - } + // } } @@ -50,14 +51,23 @@ export class RestoPageComponent implements OnInit { } + restauLiked(){ forkJoin({ restaurants: this.apiBackService.getRestaurants(), - user: this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()) - }).subscribe(({restaurants, user}) => { - - this.listRestaurants = restaurants; + user: this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()), + restauByCat : this.apiBackService.restoByCat + }).subscribe(({restaurants, user, restauByCat}) => { + + + if(this.beforeRoute === "filtres"){ + this.listRestaurants = this.apiBackService.restoFilter; + }else if(this.beforeRoute === "categories" ){ + this.listRestaurants = restauByCat + }else{ + this.listRestaurants = restaurants; + } this.listPref = user.preference;