import {Component, inject, OnInit, signal} from '@angular/core'; // Importation de la fonction input() et des components import {BooksService, GetBookDto} from "../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; import {NzTableComponent} from "ng-zorro-antd/table"; import {NzDividerComponent} from "ng-zorro-antd/divider"; import {UpdateBook} from "../update-book/update-book"; import {ModalIcon} from "../modal-icon/modal-icon"; import {NzIconDirective} from "ng-zorro-antd/icon"; @Component({ selector: 'app-book-table', imports: [ NzTableComponent, NzDividerComponent, UpdateBook, ModalIcon, NzIconDirective, ], templateUrl: './book-table.html', styleUrl: './book-table.css', }) export class BookTable implements OnInit { private booksService = inject(BooksService); private notificationService = inject(NzNotificationService) books = signal([]); booksLoading = signal(false); async ngOnInit() { await this.fetchbooks(); } async fetchbooks() { this.booksLoading.set(true) try { const books = await firstValueFrom(this.booksService.getAllBooksEndpoint()); this.books.set(books); } catch (e) { this.notificationService.error( 'Erreur', 'Erreur de communication avec l\'API' ) } this.booksLoading.set(false) } delete() { return } }