Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: signal implementation for auto-refresh button #1231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/app/components/auto-refresh-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, OnInit, Output, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, computed, inject, signal } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
Expand All @@ -21,35 +21,39 @@ import { IconsService } from '@services/icons.service';
MatDialogModule,
MatButtonModule,
MatIconModule,
]
],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AutoRefreshButtonComponent implements OnInit{
private readonly iconsService = inject(IconsService);
intervalDisplay: string;
@Input({ required: true }) intervalValue: number;

private readonly _intervalValue = signal<number>(-1);
private readonly _isDisabled = computed(() => this._intervalValue() === 0);

@Input({ required: true }) set intervalValue(value: number) {
this._intervalValue.set(value);
}

get isDisabled(): boolean {
return this._isDisabled();
}

get intervalValue() {
return this._intervalValue();
}

@Output() intervalValueChange: EventEmitter<number> = new EventEmitter<number>();

constructor(private readonly _dialog: MatDialog) { }

private _isDisabled = false;

ngOnInit(): void {
this.intervalDisplay = this.intervalValue === 0 ? $localize`:Button disabled@@autoRefreshButton:Disabled` : (this.intervalValue + $localize` seconds`);
this.setDisabled();
this.intervalDisplay = this.isDisabled ? $localize`:Button disabled@@autoRefreshButton:Disabled` : (this.intervalValue + $localize` seconds`);
}

getIcon(name: string): string {
return this.iconsService.getIcon(name);
}

setDisabled() {
this._isDisabled = this.intervalValue === 0;
}

get isDisabled(): boolean {
return this._isDisabled;
}

emit(value: number): void {
this.intervalValueChange.emit(value);
Expand All @@ -65,7 +69,6 @@ export class AutoRefreshButtonComponent implements OnInit{
dialogRef.afterClosed().subscribe(value => {
if (value !== undefined) {
this.intervalValue = value;
this.setDisabled();
this.intervalDisplay = this.isDisabled ? $localize`:Button disabled@@autoRefreshButton:Disabled` : (this.intervalValue + $localize` seconds`);
this.emit(value);
}
Expand Down
Loading