import { Component , OnInit } from '@angular/core' ; import { Router } from '@angular/router' ; import { ArticleListConfig , TagsService , UserService } from '../core' ; @ Component ( { selector : 'app-home-page' , templateUrl : './home.component.html' , styleUrls : [ './home.component.css' ] } ) export class HomeComponent implements OnInit { constructor ( private router , private tagsService , private userService ) { } isAuthenticated : boolean ; listConfig : ArticleListConfig = { type : 'all' , filters : { } } ; tags : Array < string > = [ ] ; tagsLoaded = false ; ngOnInit ( ) { this . userService . isAuthenticated . subscribe ( ( authenticated ) => { this . isAuthenticated = authenticated ; if ( authenticated ) { this . setListTo ( 'feed' ) ; } else { this . setListTo ( 'all' ) ; } } ) ; this . tagsService . getAll ( ) . subscribe ( tags => { this . tags = tags ; this . tagsLoaded = true ; } ) ; } setListTo ( type = '' , filters = { } ) { if ( type === 'feed' && ! this . isAuthenticated ) { this . router . navigateByUrl ( '/login' ) ; return ; } this . listConfig = { type : type , filters : filters } ; } }