fix(metadata): refactor book metadata fetching to use fetch API and signals for state management (#495)
* fix(metadata): refactor book metadata fetching to use fetch API and signals for state management * fix(metadata): update tests to mock fetch API for book metadata streaming * fix(metadata): improve metadata fetching with error handling and retry logic * fix(metadata): update author photo search to use SSE with auth headers and improve error handling * fix(metadata): require bookId for cover fetching and improve error handling * fix(metadata): simplify error handling in DuckDuckGo cover image fetching * fix(metadata): refactor SSE data handling for cover image and book metadata fetching
This commit is contained in:
@@ -80,23 +80,26 @@ export class CoverSearchComponent implements OnInit {
|
||||
onSearch() {
|
||||
if (this.searchForm.valid) {
|
||||
this.loading = true;
|
||||
this.coverImages = [];
|
||||
const request: CoverFetchRequest = {
|
||||
bookId: this.bookId,
|
||||
title: this.searchForm.value.title,
|
||||
author: this.searchForm.value.author,
|
||||
coverType: this.coverType
|
||||
};
|
||||
|
||||
this.bookCoverService.fetchBookCovers(request)
|
||||
.pipe(finalize(() => this.loading = false))
|
||||
.pipe(finalize(() => {
|
||||
this.loading = false;
|
||||
this.hasSearched = true;
|
||||
}))
|
||||
.subscribe({
|
||||
next: (images) => {
|
||||
this.coverImages = images.sort((a, b) => a.index - b.index);
|
||||
this.hasSearched = true;
|
||||
next: (image) => {
|
||||
this.coverImages.push(image);
|
||||
this.coverImages.sort((a, b) => a.index - b.index);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error fetching covers:', error);
|
||||
this.coverImages = [];
|
||||
this.hasSearched = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user