1- import { Component , Inject , inject , OnInit , PLATFORM_ID } from '@angular/core' ;
1+ import { Component , inject } from '@angular/core' ;
22import { MatButton } from '@angular/material/button' ;
33import { PokemonListComponent } from '../../components/pokemon-list/pokemon-list.component' ;
44import { MatDialog } from '@angular/material/dialog' ;
55import { PopupComponent } from '../../components/popup/popup.component' ;
66import { FormComponent } from '../../components/form/form.component' ;
7- import {
8- isPlatformBrowser ,
9- NgOptimizedImage ,
10- provideImgixLoader ,
11- } from '@angular/common' ;
7+ import { NgOptimizedImage , provideImgixLoader } from '@angular/common' ;
128import { BannerGridComponent } from '../../components/banner-grid/banner-grid.component' ;
13- import { BreakpointObserver , Breakpoints } from '@angular/cdk/layout' ;
14- import { DeviceDetectorService } from 'ngx-device-detector' ;
159
1610@Component ( {
1711 selector : 'app-pokedex' ,
@@ -29,66 +23,10 @@ import { DeviceDetectorService } from 'ngx-device-detector';
2923 provideImgixLoader ( 'https://ng-pokedex-optimization.netlify.app/' ) ,
3024 ] ,
3125} )
32- export class PokedexComponent implements OnInit {
26+ export class PokedexComponent {
3327 public hideForm = true ;
3428
35- public banners = {
36- mobile : '/assets/images/pokemon-banner-mobile.webp' ,
37- desktop : '/assets/images/pokemon-banner.webp' ,
38- } ;
39- // initialising the banner with a default value
40- public banner = this . banners . mobile ;
41-
42- private breakpointObserver = inject ( BreakpointObserver ) ;
4329 private dialog = inject ( MatDialog ) ;
44- private deviceService = inject ( DeviceDetectorService ) ;
45-
46- private isUserAgentMobile = this . deviceService . isMobile ( ) ;
47-
48- constructor ( @Inject ( PLATFORM_ID ) private platformId : any ) { }
49-
50- public ngOnInit ( ) {
51- if ( isPlatformBrowser ( this . platformId ) ) {
52- if ( ! this . isUserAgentMobile ) {
53- this . banner = this . banners . desktop ;
54- }
55-
56- // if mobile, skip the banner overwrite and the breakpoint observer logic
57- if ( this . isUserAgentMobile ) {
58- return ;
59- }
60-
61- // if desktop we also set up breakpoint observers, so that we load the correct banners
62- // in case the user resizes the browser window
63- this . breakpointObserver
64- . observe ( [
65- Breakpoints . XSmall ,
66- Breakpoints . Small ,
67- Breakpoints . Medium ,
68- Breakpoints . Large ,
69- Breakpoints . XLarge ,
70- ] )
71- . subscribe ( result => {
72- if ( result . matches ) {
73- if ( result . breakpoints [ Breakpoints . XSmall ] ) {
74- this . banner = this . banners . mobile ;
75- }
76- if ( result . breakpoints [ Breakpoints . Small ] ) {
77- this . banner = this . banners . mobile ;
78- }
79- if ( result . breakpoints [ Breakpoints . Medium ] ) {
80- this . banner = this . banners . desktop ;
81- }
82- if ( result . breakpoints [ Breakpoints . Large ] ) {
83- this . banner = this . banners . desktop ;
84- }
85- if ( result . breakpoints [ Breakpoints . XLarge ] ) {
86- this . banner = this . banners . desktop ;
87- }
88- }
89- } ) ;
90- }
91- }
9230
9331 openDialog ( ) : void {
9432 const dialogRef = this . dialog . open ( PopupComponent , {
0 commit comments