11import { Component , OnInit , ViewEncapsulation } from '@angular/core' ;
2- import { ActivatedRoute } from '@angular/router' ;
2+ import { ActivatedRoute , Router } from '@angular/router' ;
33
44import { FeedService } from '@services/feed.service' ;
55
66import { Feed } from '@models/feed.model' ;
7+ import { forkJoin } from 'rxjs' ;
78// use encapsulation to styles works correctly from css files
89@Component ( {
910 selector : 'app-feed' ,
@@ -14,21 +15,34 @@ import { Feed } from '@models/feed.model';
1415export class FeedComponent implements OnInit {
1516 public feed : Feed ;
1617 public recentsFeed : Feed [ ] ;
18+ public isLoading : boolean = true ;
1719
1820 constructor (
1921 private activatedRoute : ActivatedRoute ,
2022 private feedService : FeedService ,
23+ private router : Router
2124 ) { }
2225
2326 ngOnInit ( ) : void {
24- this . recentsFeed = this . feedService . getRecentsFeeds ;
25- this . activatedRoute . params . subscribe ( ( { feedID } ) => this . getFeed ( feedID ) ) ;
27+ this . activatedRoute . params . subscribe ( ( { feedID } ) => this . loadData ( feedID ) ) ;
2628 }
2729
28- getFeed ( id : string ) : void {
29- this . feedService . getFeed ( id ) . subscribe ( ( feed : Feed ) => {
30- this . feed = feed ;
30+ loadData ( id : string ) : void {
31+ this . isLoading = true ;
32+ forkJoin ( {
33+ feed : this . feedService . getFeed ( id ) ,
34+ recentFeeds : this . feedService . getFeeds ( 0 , 6 , false ) ,
35+ } ) . subscribe ( {
36+ next : ( { feed, recentFeeds } ) => {
37+ this . feed = feed ,
38+ this . recentsFeed = recentFeeds ;
39+ } ,
40+ complete : ( ) => this . isLoading = false ,
3141 } )
3242 }
3343
44+ goToFeed ( id : string ) : void {
45+ this . router . navigate ( [ `/feed/${ id } ` ] ) ;
46+ }
47+
3448}
0 commit comments