Add notification and handler for metadata update
This commit is contained in:
@@ -27,6 +27,10 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
});
|
||||
|
||||
this.rxStompService.watch('/topic/metadata-update').subscribe((message: Message) => {
|
||||
this.bookService.handleUpdateMetadata(JSON.parse(message.body));
|
||||
});
|
||||
|
||||
this.rxStompService.watch('/topic/log').subscribe((message: Message) => {
|
||||
let logNotification = parseLogNotification(message.body);
|
||||
this.eventService.handleIncomingLog(logNotification);
|
||||
|
||||
@@ -205,4 +205,12 @@ export class BookService {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
handleUpdateMetadata(updatedBook: Book) {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
const updatedBooks = (currentState.books || []).map(book => {
|
||||
return book.id == updatedBook.id ? {...book, metadata: updatedBook.metadata} : book
|
||||
});
|
||||
this.bookStateSubject.next({...currentState, books: updatedBooks})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user