mirror of
https://github.com/block-core/angor-hub-old.git
synced 2026-01-31 07:34:21 +01:00
Refactor UpdateComponent: replaced async pipe with signal, removed unnecessary imports and decorators, and updated template to use conditional rendering
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<!-- Update toggle -->
|
||||
<button
|
||||
*ngIf="updateService.isNewVersionAvailable$ | async"
|
||||
mat-icon-button
|
||||
[matTooltip]="tooltip || 'Update App'"
|
||||
(click)="applyUpdate()"
|
||||
>
|
||||
<mat-icon [svgIcon]="'heroicons_outline:cloud-arrow-down'"></mat-icon>
|
||||
</button>
|
||||
@if (isNewVersionAvailable()) {
|
||||
<button
|
||||
mat-icon-button
|
||||
[matTooltip]="tooltip()"
|
||||
(click)="applyUpdate()"
|
||||
>
|
||||
<mat-icon [svgIcon]="'heroicons_outline:cloud-arrow-down'"></mat-icon>
|
||||
</button>
|
||||
}
|
||||
|
||||
@@ -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<string> = 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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user