From d15a78c60bc1a59f5ed299742e578a3c19d5755a Mon Sep 17 00:00:00 2001 From: Milad Raeisi Date: Wed, 4 Dec 2024 06:47:55 +0400 Subject: [PATCH] Refactor UpdateComponent: replaced async pipe with signal, removed unnecessary imports and decorators, and updated template to use conditional rendering --- .../common/update/update.component.html | 18 ++++---- .../layout/common/update/update.component.ts | 41 ++++++++----------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/app/layout/common/update/update.component.html b/src/app/layout/common/update/update.component.html index d645f29..d2d7882 100644 --- a/src/app/layout/common/update/update.component.html +++ b/src/app/layout/common/update/update.component.html @@ -1,9 +1,9 @@ - - +@if (isNewVersionAvailable()) { + +} diff --git a/src/app/layout/common/update/update.component.ts b/src/app/layout/common/update/update.component.ts index c36a8a6..8e3d516 100644 --- a/src/app/layout/common/update/update.component.ts +++ b/src/app/layout/common/update/update.component.ts @@ -1,48 +1,39 @@ -import { - CommonModule, - DatePipe, - NgClass, - NgTemplateOutlet, -} from '@angular/common'; import { ChangeDetectionStrategy, - ChangeDetectorRef, Component, - Input, - ViewEncapsulation, + Signal, + inject, + signal, + effect, } from '@angular/core'; +import { CommonModule } from '@angular/common'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatTooltipModule } from '@angular/material/tooltip'; -import { RouterLink } from '@angular/router'; import { NewVersionCheckerService } from 'app/services/update.service'; @Component({ selector: 'update', - templateUrl: './update.component.html', - encapsulation: ViewEncapsulation.None, - changeDetection: ChangeDetectionStrategy.OnPush, - exportAs: 'update', standalone: true, imports: [ + CommonModule, MatButtonModule, MatIconModule, MatTooltipModule, - CommonModule, - ] + ], + templateUrl: './update.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, }) export class UpdateComponent { - @Input() tooltip: string; + tooltip: Signal = signal('Update App'); - constructor( - public updateService: NewVersionCheckerService, - private _changeDetectorRef: ChangeDetectorRef // Injecting ChangeDetectorRef - ) { - // Listen to the update available event and trigger change detection + isNewVersionAvailable = signal(false); + + private updateService = inject(NewVersionCheckerService); + + constructor() { this.updateService.isNewVersionAvailable$.subscribe((isAvailable) => { - if (isAvailable) { - this._changeDetectorRef.detectChanges(); // Trigger change detection - } + this.isNewVersionAvailable.set(isAvailable); }); }