Fix library creator component

This commit is contained in:
aditya.chandel
2025-01-02 16:02:36 -07:00
parent 0e6ef1da5e
commit 83d0a761ae
3 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ import { LoadingOverlayComponent } from './loading-overlay/loading-overlay.compo
LibraryCreatorComponent, LibraryCreatorComponent,
ShelfAssignerComponent, ShelfAssignerComponent,
BookBrowserComponent, BookBrowserComponent,
MetadataSearcherComponent MetadataSearcherComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@@ -74,9 +74,7 @@ export class BookCardComponent implements OnInit {
{ {
label: 'View metadata', label: 'View metadata',
icon: 'pi pi-info-circle', icon: 'pi pi-info-circle',
command: () => { command: () => this.openBookInfo(this.book),
this.openBookInfo(this.book)
},
}, },
], ],
}, },
@@ -98,6 +96,8 @@ export class BookCardComponent implements OnInit {
} }
openBookInfo(book: Book): void { 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);
} }
} }
@@ -5,6 +5,7 @@ import {MessageService} from 'primeng/api';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {LibraryService} from '../../service/library.service'; import {LibraryService} from '../../service/library.service';
import {IconPickerComponent} from '../icon-picker/icon-picker.component'; import {IconPickerComponent} from '../icon-picker/icon-picker.component';
import {take} from 'rxjs';
@Component({ @Component({
selector: 'app-library-creator', selector: 'app-library-creator',
@@ -97,10 +98,12 @@ export class LibraryCreatorComponent {
validateLibraryNameAndProceed(activateCallback: Function) { validateLibraryNameAndProceed(activateCallback: Function) {
if (this.libraryName.trim()) { if (this.libraryName.trim()) {
this.libraryService.libraryState$.subscribe( const libraryName = this.libraryName.trim();
libraryState => { this.libraryService.libraryState$
let library = libraryState.libraries?.find(library => library.name === this.libraryName.trim()); .pipe(take(1))
if(library) { .subscribe(libraryState => {
const library = libraryState.libraries?.find(library => library.name === libraryName);
if (library) {
this.messageService.add({ this.messageService.add({
severity: 'error', severity: 'error',
summary: 'Library Name Exists', summary: 'Library Name Exists',
@@ -109,8 +112,7 @@ export class LibraryCreatorComponent {
} else { } else {
activateCallback(2); activateCallback(2);
} }
} });
)
} }
} }