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,67 +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-
40- // initialising the banner with a default value
41- public banner = this . banners . mobile ;
42-
43- private breakpointObserver = inject ( BreakpointObserver ) ;
4429 private dialog = inject ( MatDialog ) ;
45- private deviceService = inject ( DeviceDetectorService ) ;
46-
47- private isUserAgentMobile = this . deviceService . isMobile ( ) ;
48-
49- constructor ( @Inject ( PLATFORM_ID ) private platformId : any ) { }
50-
51- public ngOnInit ( ) {
52- if ( isPlatformBrowser ( this . platformId ) ) {
53- if ( ! this . isUserAgentMobile ) {
54- this . banner = this . banners . desktop ;
55- }
56-
57- // if mobile, skip the banner overwrite and the breakpoint observer logic
58- if ( this . isUserAgentMobile ) {
59- return ;
60- }
61-
62- // if desktop we also set up breakpoint observers, so that we load the correct banners
63- // in case the user resizes the browser window
64- this . breakpointObserver
65- . observe ( [
66- Breakpoints . XSmall ,
67- Breakpoints . Small ,
68- Breakpoints . Medium ,
69- Breakpoints . Large ,
70- Breakpoints . XLarge ,
71- ] )
72- . subscribe ( result => {
73- if ( result . matches ) {
74- if ( result . breakpoints [ Breakpoints . XSmall ] ) {
75- this . banner = this . banners . mobile ;
76- }
77- if ( result . breakpoints [ Breakpoints . Small ] ) {
78- this . banner = this . banners . mobile ;
79- }
80- if ( result . breakpoints [ Breakpoints . Medium ] ) {
81- this . banner = this . banners . desktop ;
82- }
83- if ( result . breakpoints [ Breakpoints . Large ] ) {
84- this . banner = this . banners . desktop ;
85- }
86- if ( result . breakpoints [ Breakpoints . XLarge ] ) {
87- this . banner = this . banners . desktop ;
88- }
89- }
90- } ) ;
91- }
92- }
9330
9431 openDialog ( ) : void {
9532 const dialogRef = this . dialog . open ( PopupComponent , {
0 commit comments