Load books only when needed not in constructor

This commit is contained in:
aditya.chandel
2025-01-17 22:03:12 -07:00
parent 42ccd2ce4d
commit ad741440b4
4 changed files with 15 additions and 9 deletions
@@ -91,6 +91,7 @@ export class BookBrowserComponent implements OnInit {
private libraryShelfMenuService = inject(LibraryShelfMenuService);
ngOnInit(): void {
this.bookService.loadBooks();
this.sortOptions = SortService.generateSortOptions();
const isAllBooksRoute = this.activatedRoute.snapshot.routeConfig?.path === 'all-books';
@@ -20,11 +20,11 @@ export class BookService {
private http = inject(HttpClient);
constructor() {
this.loadBooks();
}
private loadBooks(): void {
loadBooks(): void {
const currentState = this.bookStateSubject.value;
if (currentState.loaded) {
return;
}
this.http.get<Book[]>(this.url).pipe(
tap(books => {
this.bookStateSubject.next({