Skip to content

Instantly share code, notes, and snippets.

@umutyerebakmaz
Created April 7, 2023 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umutyerebakmaz/7fe14dc5a00fda1534bf380cfa0f8894 to your computer and use it in GitHub Desktop.
Save umutyerebakmaz/7fe14dc5a00fda1534bf380cfa0f8894 to your computer and use it in GitHub Desktop.
import { ChangeDetectionStrategy, Component, HostListener, Inject, OnInit, OnDestroy } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Observable, tap } from 'rxjs';
import { InsectInfoDialogQuery } from '@generated-types';
import { InsectService } from '@app/services/insect.service';
export interface InsectInfoDialogData {
id: string;
}
@Component({
selector: 'insect-info-dialog',
templateUrl: './insect-info-dialog.component.html',
styleUrls: ['./insect-info-dialog.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class InsectInfoDialogComponent implements OnInit, OnDestroy {
loading = false;
insectInfoDialog$!: Observable<InsectInfoDialogQuery['insect']>;
constructor(
@Inject(MAT_DIALOG_DATA) public data: InsectInfoDialogData,
private dialogRef: MatDialogRef<InsectInfoDialogComponent>,
private insectService: InsectService
) {}
ngOnInit(): void {
this.getInsectInfoDialogData(this.data.id);
}
ngOnDestroy(): void {
this.dialogRef.close();
}
@HostListener('keydown.esc')
close() {
this.dialogRef.close();
}
getInsectInfoDialogData(id: string) {
this.loading = true;
this.insectInfoDialog$ = this.insectService.infoDialog(id).pipe(
tap({
next: () => {
this.loading = false;
},
error: (error: Error) => {
this.loading = true;
},
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment