Optimized code (significantly)

This commit is contained in:
ItzMineyy committed 2024-12-28 20:50:18 +01:00
1 parent 5fbb41c477
commit a4b69c5b9a
31 files changed
+343 -441

No files matched your search

+13 -27
View File
@@ -1,48 +1,35 @@
import { Component, OnInit, Inject, PLATFORM_ID} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {NgIf} from '@angular/common';
import { DeviceDetectorService } from 'ngx-device-detector';
import {RouterOutlet, ActivatedRoute, Router, NavigationEnd} from '@angular/router';
import {ActivatedRoute, NavigationEnd, Router, RouterOutlet} from '@angular/router';
import {NavbarComponent} from './navbar/navbar.component';
import {MobileNavbarComponent} from './mobile-navbar/mobile-navbar.component';
import {FooterComponent} from './footer/footer.component';
import { Title, Meta } from '@angular/platform-browser';
import { filter, map, mergeMap } from 'rxjs/operators';
import { isPlatformBrowser } from '@angular/common';
import {subscribe} from 'node:diagnostics_channel';
import {Meta, Title} from '@angular/platform-browser';
import {filter, map, mergeMap} from 'rxjs/operators';
import {DeviceDetectorService} from './services/device-detector.service';
@Component({
selector: 'app-root',
imports: [RouterOutlet, NavbarComponent, FooterComponent, MobileNavbarComponent, NgIf],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
styleUrl: './app.component.css',
})
export class AppComponent implements OnInit {
isMobile: boolean;
isMobile: boolean = false;
showNavbar: boolean = true;
showFooter: boolean = true;
constructor(
private deviceService: DeviceDetectorService,
private router: Router,
private activatedRoute: ActivatedRoute,
private titleService: Title,
private metaService: Meta,
@Inject(PLATFORM_ID) private platformId: Object
) {
if (isPlatformBrowser(this.platformId)) {
// Use client-side logic to determine if it's mobile
this.isMobile = window.innerWidth <= 768; // Adjust breakpoint as needed
} else {
// Default fallback for SSR
this.isMobile = false; // Or any other logic to handle SSR
}
}
private deviceService: DeviceDetectorService,
) {}
ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
this.isMobile = window.innerWidth <= 768;
}
this.isMobile = this.deviceService.isMobile;
this.router.events
.pipe(
filter(event => event instanceof NavigationEnd),
@@ -56,7 +43,7 @@ export class AppComponent implements OnInit {
.subscribe(data => {
const meta = data['meta'] || {};
if (this.router.url === '/about') {
// fallback meta
// fallback meta data
meta.title = meta.title || 'itzMiney\'s Home';
meta.description = meta.description || 'Welcome to itzMiney\'s Homepage! Here you can find my portfolio and other cool stuff.';
meta.image = meta.image || 'https://itzminey.dev/assets/ogimg.png';
@@ -66,7 +53,6 @@ export class AppComponent implements OnInit {
this.updateMetaTags(meta);
this.checkRoute();
});
this.checkRoute();
}
updateMetaTags(meta: { title?: string; description?: string; image?: string; url?: string; color?: string }) {
@@ -92,7 +78,7 @@ export class AppComponent implements OnInit {
checkRoute() {
const currentRoute = this.activatedRoute.snapshot.firstChild?.routeConfig?.path;
// Hide navbar and footer on admin route
switch (currentRoute) {
case 'admin': {
this.showNavbar = false;