import { Component , OnInit } from '@angular/core' ; import { Store , Select } from '@ngxs/store' ; import { Router } from '@angular/router' ; import { environment } from '../../../environments/environment' ; import { GetCoffeeList , AddToCart } from '../../state/app.actions' ; import { AppState } from '../../state/app.state' ; @ Component ( { selector : 'app-list-page' , templateUrl : './list-page.component.html' , styleUrls : [ './list-page.component.css' ] } ) export class ListPageComponent implements OnInit { @ Select ( AppState . coffeeList ) list$ ; isFeatureRemixOn = environment . features . remix ; constructor ( private router , private store ) { } ngOnInit ( ) { const isListPopulated = this . store . selectSnapshot < App > ( x => x . app . coffeeList . length ) ; if ( isListPopulated ) { return ; } this . store . dispatch ( new GetCoffeeList ( ) ) ; } addToCart ( name ) { this . store . dispatch ( new AddToCart ( name ) ) ; } addToCartAndCheckout ( name ) { this . addToCart ( name ) ; this . router . navigateByUrl ( '/cart' ) ; } }