refactor to define helper service more accurately
This commit is contained in:
1 parent
5527acfb6a
commit
7618e4bf5d
28 files changed
+78
-403
No files matched your search
@@ -1,4 +1,4 @@
|
||||
<div class="audio-player" [ngClass]="{ mobile: isMobile }">
|
||||
<div class="audio-player" [ngClass]="{ mobile: isNarrow }">
|
||||
<div id="youtube-player"></div>
|
||||
<h3>{{ nowPlayingTitle() }}</h3>
|
||||
<div class="controls">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {Component, AfterViewInit, signal, OnInit} from '@angular/core';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {ViewportService} from '../services/viewport.service';
|
||||
import {NgClass} from '@angular/common';
|
||||
|
||||
|
||||
@@ -19,17 +19,17 @@ declare global {
|
||||
styleUrl: './audio-player.component.css'
|
||||
})
|
||||
export class AudioPlayerComponent implements AfterViewInit, OnInit {
|
||||
isMobile: boolean = false;
|
||||
isNarrow: boolean = false;
|
||||
private player: any;
|
||||
|
||||
isPlayerReady = signal(false);
|
||||
isPlaying = signal(false);
|
||||
nowPlayingTitle = signal<string>('');
|
||||
|
||||
constructor(private deviceService: DeviceDetectorService) {}
|
||||
constructor(private deviceService: ViewportService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {ViewportService} from '../services/viewport.service';
|
||||
|
||||
import {NavigationEnd, Router, RouterLink} from '@angular/router';
|
||||
import {TranslatePipe, TranslateService} from '@ngx-translate/core';
|
||||
@@ -17,15 +17,15 @@ import {TranslatePipe, TranslateService} from '@ngx-translate/core';
|
||||
export class MobileNavbarComponent implements OnInit{
|
||||
currentLang: string;
|
||||
menuOpen = false;
|
||||
isMobile: boolean = false;
|
||||
isNarrow: boolean = false;
|
||||
activeLink: string = '';
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private deviceService: DeviceDetectorService,
|
||||
private deviceService: ViewportService,
|
||||
private translate: TranslateService
|
||||
) {
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
this.currentLang = this.translate.currentLang || this.translate.getDefaultLang() || 'en';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {NavigationEnd, Router, RouterLink} from '@angular/router';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {ViewportService} from '../services/viewport.service';
|
||||
import {filter} from 'rxjs/operators';
|
||||
import {TranslatePipe, TranslateService} from '@ngx-translate/core';
|
||||
|
||||
@@ -16,14 +16,14 @@ import {TranslatePipe, TranslateService} from '@ngx-translate/core';
|
||||
export class NavbarComponent implements OnInit {
|
||||
currentLang: string;
|
||||
activeLink: string = '';
|
||||
isMobile: boolean = false;
|
||||
isNarrow: boolean = false;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private deviceService: DeviceDetectorService,
|
||||
private deviceService: ViewportService,
|
||||
private translate: TranslateService
|
||||
) {
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
this.currentLang = this.translate.currentLang || this.translate.getDefaultLang() || 'en';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {AfterViewInit, Component, ElementRef, Inject, OnDestroy, OnInit, PLATFORM_ID, ViewChild, Input} from '@angular/core';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {ViewportService} from '../services/viewport.service';
|
||||
import {isPlatformBrowser} from '@angular/common';
|
||||
import Parallax from 'parallax-js';
|
||||
|
||||
@@ -16,17 +16,17 @@ export class ParallaxComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
@Input() bgGradient: string =
|
||||
'radial-gradient(circle 120vw at center, rgba(90,78,130,0.32), transparent 40%), linear-gradient(180deg,#1b172c 0%, #0b0b0f 100%)';
|
||||
|
||||
isMobile: boolean = false;
|
||||
isNarrow: boolean = false;
|
||||
private parallaxInstance: Parallax | null = null;
|
||||
|
||||
constructor(
|
||||
private deviceService: DeviceDetectorService,
|
||||
private deviceService: ViewportService,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@@ -39,8 +39,8 @@ export class ParallaxComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
clipRelativeInput: true,
|
||||
calibrateX: true,
|
||||
calibrateY: true,
|
||||
scalarX: this.isMobile ? 6 : 12,
|
||||
scalarY: this.isMobile ? 6 : 12,
|
||||
scalarX: this.isNarrow ? 6 : 12,
|
||||
scalarY: this.isNarrow ? 6 : 12,
|
||||
frictionX: 0.1,
|
||||
frictionY: 0.1,
|
||||
});
|
||||
|
||||
+4
-4
@@ -4,8 +4,8 @@ import {isPlatformBrowser} from '@angular/common';
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DeviceDetectorService {
|
||||
isMobile: boolean = false;
|
||||
export class ViewportService {
|
||||
isNarrow: boolean = false;
|
||||
|
||||
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
|
||||
this.updateDeviceType();
|
||||
@@ -16,9 +16,9 @@ export class DeviceDetectorService {
|
||||
|
||||
private updateDeviceType() {
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
this.isMobile = window.innerWidth <= 768;
|
||||
this.isNarrow = window.innerWidth <= 768;
|
||||
} else {
|
||||
this.isMobile = false;
|
||||
this.isNarrow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user