Implement synchronous quick refresh

This commit is contained in:
aditya.chandel
2025-01-26 18:02:42 -07:00
parent 67581cf3ea
commit d7cb1c1846
8 changed files with 55 additions and 15 deletions
@@ -1,4 +1,7 @@
<form [formGroup]="metadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
<div *ngIf="isLoading" class="absolute inset-0 bg-black opacity-25 z-10"></div>
<p-progressSpinner *ngIf="isLoading" [style]="{position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)'}"></p-progressSpinner>
<div class="overflow-y-scroll flex-1">
@@ -15,8 +15,6 @@ import {FileUpload, FileUploadErrorEvent, FileUploadEvent} from 'primeng/fileupl
import {HttpResponse} from '@angular/common/http';
import {BookService} from '../../../book/service/book.service';
import {ProgressSpinner} from 'primeng/progressspinner';
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
@Component({
selector: 'app-metadata-editor',
@@ -49,6 +47,7 @@ export class MetadataEditorComponent implements OnInit {
metadataForm: FormGroup;
currentBookId!: number;
isUploading = false;
isLoading = false;
constructor() {
this.metadataForm = new FormGroup({
@@ -284,11 +283,16 @@ export class MetadataEditorComponent implements OnInit {
}
quickRefresh() {
const metadataRefreshRequest: MetadataRefreshRequest = {
quick: true,
refreshType: MetadataRefreshType.BOOKS,
bookIds: [this.currentBookId]
};
this.metadataService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
this.isLoading = true;
this.metadataService.quickUpdateBookMetadataSynchronous(this.currentBookId).subscribe({
next: (bookMetadata) => {
this.isLoading = false;
this.metadataCenterService.emit(bookMetadata);
},
error: () => {
this.isLoading = false;
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update metadata'});
}
});
}
}
@@ -24,6 +24,15 @@ export class MetadataService {
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}`, request);
}
quickUpdateBookMetadataSynchronous(bookId: number): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}/refresh-book-sync`, {}).pipe(
map(updatedMetadata => {
this.bookService.handleBookMetadataUpdate(bookId, updatedMetadata);
return updatedMetadata;
})
);
}
updateBookMetadata(bookId: number, bookMetadata: BookMetadata): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}`, bookMetadata).pipe(
map(updatedMetadata => {