From 83d0a761ae74e8b3c516776c3bb1985f9e8090fe Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Thu, 2 Jan 2025 16:02:36 -0700 Subject: [PATCH] Fix library creator component --- booklore-ui/src/app/app.module.ts | 2 +- .../component/book-card/book-card.component.ts | 8 ++++---- .../library-creator/library-creator.component.ts | 14 ++++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/booklore-ui/src/app/app.module.ts b/booklore-ui/src/app/app.module.ts index a8154548a..fe1776569 100644 --- a/booklore-ui/src/app/app.module.ts +++ b/booklore-ui/src/app/app.module.ts @@ -52,7 +52,7 @@ import { LoadingOverlayComponent } from './loading-overlay/loading-overlay.compo LibraryCreatorComponent, ShelfAssignerComponent, BookBrowserComponent, - MetadataSearcherComponent + MetadataSearcherComponent, ], imports: [ BrowserModule, diff --git a/booklore-ui/src/app/book/component/book-card/book-card.component.ts b/booklore-ui/src/app/book/component/book-card/book-card.component.ts index 0eaa938f9..c437d3216 100644 --- a/booklore-ui/src/app/book/component/book-card/book-card.component.ts +++ b/booklore-ui/src/app/book/component/book-card/book-card.component.ts @@ -74,9 +74,7 @@ export class BookCardComponent implements OnInit { { label: 'View metadata', icon: 'pi pi-info-circle', - command: () => { - this.openBookInfo(this.book) - }, + command: () => this.openBookInfo(this.book), }, ], }, @@ -98,6 +96,8 @@ export class BookCardComponent implements OnInit { } openBookInfo(book: Book): void { - this.router.navigate(['/library', book.libraryId, 'book', book.id, 'info']); + setTimeout(() => { + this.router.navigate(['/library', book.libraryId, 'book', book.id, 'info']); + }, 10); } } diff --git a/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts b/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts index c6dfbefb0..2d725d38b 100644 --- a/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts +++ b/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts @@ -5,6 +5,7 @@ import {MessageService} from 'primeng/api'; import {Router} from '@angular/router'; import {LibraryService} from '../../service/library.service'; import {IconPickerComponent} from '../icon-picker/icon-picker.component'; +import {take} from 'rxjs'; @Component({ selector: 'app-library-creator', @@ -97,10 +98,12 @@ export class LibraryCreatorComponent { validateLibraryNameAndProceed(activateCallback: Function) { if (this.libraryName.trim()) { - this.libraryService.libraryState$.subscribe( - libraryState => { - let library = libraryState.libraries?.find(library => library.name === this.libraryName.trim()); - if(library) { + const libraryName = this.libraryName.trim(); + this.libraryService.libraryState$ + .pipe(take(1)) + .subscribe(libraryState => { + const library = libraryState.libraries?.find(library => library.name === libraryName); + if (library) { this.messageService.add({ severity: 'error', summary: 'Library Name Exists', @@ -109,8 +112,7 @@ export class LibraryCreatorComponent { } else { activateCallback(2); } - } - ) + }); } }