Skip to content

Commit

Permalink
app component refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetcetin01140 committed Nov 28, 2023
1 parent a055e11 commit 80c0446
Showing 1 changed file with 25 additions and 37 deletions.
62 changes: 25 additions & 37 deletions src/app/showcase/layout/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { Component, Inject, OnDestroy, OnInit, PLATFORM_ID, Renderer2 } from '@angular/core';
import { AfterViewInit, Component, Inject, OnDestroy, OnInit, PLATFORM_ID, Renderer2 } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute, NavigationEnd, Router, RouterOutlet} from '@angular/router';
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
import { PrimeNGConfig } from 'primeng/api';
import { Subscription } from 'rxjs';
import { Theme } from '../domain/theme';
Expand All @@ -29,38 +29,10 @@ import { AppTopBarComponent } from './topbar/app.topbar.component';
imports: [RouterOutlet, FormsModule, ReactiveFormsModule, HttpClientModule, AppMainComponent, LandingComponent, AppNewsComponent, AppConfigComponent, AppTopBarComponent, AppMenuComponent],
providers: [CarService, CountryService, EventService, NodeService, IconService, CustomerService, PhotoService, AppConfigService, ProductService]
})
export class AppComponent implements OnInit, OnDestroy {
constructor(@Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, private renderer: Renderer2, private primeng: PrimeNGConfig, private configService: AppConfigService, private router: Router, private route: ActivatedRoute) {
if (isPlatformBrowser(platformId) && window && process.env.NODE_ENV === 'production') {
this.injectScripts();
}
router.events.forEach((event) => {

if(event instanceof NavigationEnd && event.url !== "/") {

this.showConfigurator = true

this.showMenuButton = true
}

else if (event instanceof NavigationEnd){


this.showConfigurator = false

this.showMenuButton = false

}

});

isPlatformBrowser(this.platformId) && this.handleRouteEvents();

}

export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
constructor(@Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, private renderer: Renderer2, private primeng: PrimeNGConfig, private configService: AppConfigService, private router: Router) {}

public themeChangeSubscription: Subscription;

showConfigurator : boolean = false

showMenuButton : boolean = false
Expand All @@ -71,9 +43,6 @@ export class AppComponent implements OnInit, OnDestroy {
this.themeChangeSubscription = this.configService.themeChange$.subscribe((theme: Theme) => {
this.switchTheme(theme);
});



}

ngAfterViewInit() {
Expand Down Expand Up @@ -104,15 +73,32 @@ export class AppComponent implements OnInit, OnDestroy {
this.renderer.appendChild(this.document.body, scriptBody);
}

handleRouteEvents() {
bindRouteEvents() {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
if (typeof window['gtag'] === 'function') {
window['gtag']('event', 'page_view', {
page_path: event.urlAfterRedirects
});
}

const { theme, darkMode } = this.configService.config;
const landingTheme = darkMode ? 'lara-dark-blue' : 'lara-light-blue';
if (event.urlAfterRedirects === '/' && theme !== landingTheme) {
this.switchTheme({ name: landingTheme, dark: darkMode });
}
}
if(event instanceof NavigationEnd && event.url !== "/") {
this.showConfigurator = true
this.showMenuButton = true
}

else if (event instanceof NavigationEnd){
this.showConfigurator = false
this.showMenuButton = false

}

});
}

Expand All @@ -136,6 +122,7 @@ export class AppComponent implements OnInit, OnDestroy {
this.configService.completeThemeChange(theme);
});
}

toggleDarkMode() {
let newTheme = null;
const { theme, darkMode } = this.configService.config;
Expand All @@ -149,9 +136,10 @@ export class AppComponent implements OnInit, OnDestroy {

this.configService.changeTheme({ name: newTheme, dark: !darkMode });
}

ngOnDestroy() {
if (this.themeChangeSubscription) {
this.themeChangeSubscription.unsubscribe();
}
}
}
}

1 comment on commit 80c0446

@vercel
Copy link

@vercel vercel bot commented on 80c0446 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.