From 36c85bfb068c2ed74c548f4ee050d022990a597a Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Fri, 20 Dec 2024 18:32:41 -0700
Subject: [PATCH] Add delete library functionality More reactivity
---
booklore-ui/src/app/app.component.html | 1 +
booklore-ui/src/app/app.component.ts | 14 +-
booklore-ui/src/app/app.module.ts | 8 +-
.../book-metadata.component.html | 4 +-
.../book-metadata/book-metadata.component.ts | 12 +-
.../books-metadata-dialog.component.ts | 4 +-
.../dashboard-scroller.component.html | 2 +-
.../dashboard-scroller.component.ts | 9 +-
.../dashboard/dashboard.component.ts | 18 +--
.../file-upload/file-upload.component.ts | 8 +-
.../component/layout/app.menu.component.ts | 9 +-
.../library-browser.component.html | 41 +++--
.../library-browser.component.scss | 7 +-
.../library-browser.component.ts | 141 ++++++++++-------
.../library-creator.component.ts | 10 +-
.../notification/notification.component.ts | 3 -
.../pdf-viewer/pdf-viewer.component.ts | 4 +-
.../book/component/search/search.component.ts | 6 +-
.../app/book/service/book-progress-service.ts | 37 -----
...service.ts => library-and-book.service.ts} | 146 ++++++++++++++----
.../src/app/book/service/library.service.ts | 46 ------
booklore-ui/src/app/rx-stomp.service.ts | 2 +
.../layout/images/banner-primeblocks-dark.png | Bin 139491 -> 0 bytes
.../layout/images/banner-primeblocks.png | Bin 139643 -> 0 bytes
24 files changed, 284 insertions(+), 248 deletions(-)
delete mode 100644 booklore-ui/src/app/book/service/book-progress-service.ts
rename booklore-ui/src/app/book/service/{book.service.ts => library-and-book.service.ts} (52%)
delete mode 100644 booklore-ui/src/app/book/service/library.service.ts
delete mode 100644 booklore-ui/src/assets/layout/images/banner-primeblocks-dark.png
delete mode 100644 booklore-ui/src/assets/layout/images/banner-primeblocks.png
diff --git a/booklore-ui/src/app/app.component.html b/booklore-ui/src/app/app.component.html
index b6df4c168..b899f0920 100644
--- a/booklore-ui/src/app/app.component.html
+++ b/booklore-ui/src/app/app.component.html
@@ -1,2 +1,3 @@
+
diff --git a/booklore-ui/src/app/app.component.ts b/booklore-ui/src/app/app.component.ts
index 7266758ee..635f46869 100644
--- a/booklore-ui/src/app/app.component.ts
+++ b/booklore-ui/src/app/app.component.ts
@@ -1,8 +1,7 @@
import {Component, OnInit} from '@angular/core';
-import {LibraryService} from './book/service/library.service';
import {RxStompService} from './rx-stomp.service';
import {Message} from '@stomp/stompjs';
-import {BookService} from './book/service/book.service';
+import {LibraryAndBookService} from './book/service/library-and-book.service';
import {Book} from './book/model/book.model';
@Component({
@@ -13,17 +12,14 @@ import {Book} from './book/model/book.model';
})
export class AppComponent implements OnInit {
- constructor(private libraryService: LibraryService, private bookService: BookService, private rxStompService: RxStompService) {
+ constructor(private libraryBookService: LibraryAndBookService, private rxStompService: RxStompService) {
}
ngOnInit(): void {
- this.libraryService.initializeLibraries();
- this.bookService.loadBooksSignal(1);
-
-
+ this.libraryBookService.initializeLibraries();
this.rxStompService.watch('/topic/books').subscribe((message: Message) => {
- const book: Book = JSON.parse(message.body); // Parse the incoming message to book DTO
- this.bookService.appendBookToLibrary(book); // Call method to append to libraryBooks
+ const book: Book = JSON.parse(message.body);
+ this.libraryBookService.handleNewBook(book);
});
}
diff --git a/booklore-ui/src/app/app.module.ts b/booklore-ui/src/app/app.module.ts
index 31b8543df..57a37bab4 100644
--- a/booklore-ui/src/app/app.module.ts
+++ b/booklore-ui/src/app/app.module.ts
@@ -19,13 +19,13 @@ import {PasswordModule} from 'primeng/password';
import {ToastModule} from 'primeng/toast';
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
import {SearchComponent} from './book/component/search/search.component';
-import {MessageService} from 'primeng/api';
-import {FileUploadComponent} from './book/component/file-upload/file-upload.component';
+import {ConfirmationService, MessageService} from 'primeng/api';
import {DropdownModule} from 'primeng/dropdown';
import {rxStompServiceFactory} from './rx-stomp-service-factory';
import {RxStompService} from './rx-stomp.service';
import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller';
import {LazyLoadImageModule} from 'ng-lazyload-image';
+import {ConfirmDialogModule} from 'primeng/confirmdialog';
@NgModule({
declarations: [
@@ -51,11 +51,13 @@ import {LazyLoadImageModule} from 'ng-lazyload-image';
SearchComponent,
DropdownModule,
VirtualScrollerModule,
- LazyLoadImageModule
+ LazyLoadImageModule,
+ ConfirmDialogModule,
],
providers: [
DialogService,
MessageService,
+ ConfirmationService,
{
provide: RxStompService,
useFactory: rxStompServiceFactory,
diff --git a/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.html b/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.html
index 69a8565b7..fd579b9f1 100644
--- a/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.html
+++ b/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.html
@@ -4,7 +4,7 @@
![Cover of {{ book?.metadata?.title }}]()
-
@@ -38,7 +38,7 @@
diff --git a/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts b/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts
index 42d187afd..13abdfac4 100644
--- a/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts
+++ b/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts
@@ -1,6 +1,6 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
-import {BookService} from '../../service/book.service';
+import {LibraryAndBookService} from '../../service/library-and-book.service';
import {Book} from '../../model/book.model';
import {Button} from 'primeng/button';
import {NgForOf, NgIf} from '@angular/common';
@@ -30,7 +30,7 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
private dialogSubscription?: Subscription;
constructor(
- private bookService: BookService, private activatedRoute: ActivatedRoute,
+ private bookService: LibraryAndBookService, private activatedRoute: ActivatedRoute,
private dialogService: DialogService, private router: Router) {
}
@@ -106,11 +106,7 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
}
}
- readBook(id: number | undefined) {
- const url = `/pdf-viewer/book/${id}`;
- window.open(url, '_blank');
- this.routeSubscription?.unsubscribe();
- this.dialogSubscription?.unsubscribe();
- this.dialogRef?.close();
+ readBook(book: Book) {
+ this.bookService.readBook(book);
}
}
diff --git a/booklore-ui/src/app/book/component/books-metadata-dialog/books-metadata-dialog.component.ts b/booklore-ui/src/app/book/component/books-metadata-dialog/books-metadata-dialog.component.ts
index 393c11638..eedb62984 100644
--- a/booklore-ui/src/app/book/component/books-metadata-dialog/books-metadata-dialog.component.ts
+++ b/booklore-ui/src/app/book/component/books-metadata-dialog/books-metadata-dialog.component.ts
@@ -1,6 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {BookMetadata} from '../../model/book.model';
-import {BookService} from '../../service/book.service';
+import {LibraryAndBookService} from '../../service/library-and-book.service';
import {NgForOf, NgIf} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
@@ -27,7 +27,7 @@ export class BooksMetadataDialogComponent implements OnInit {
bookId: number = 0;
libraryId: number = 0;
- constructor(private bookService: BookService, public dynamicDialogConfig: DynamicDialogConfig, private dynamicDialogRef: DynamicDialogRef, private router: Router) {
+ constructor(private bookService: LibraryAndBookService, public dynamicDialogConfig: DynamicDialogConfig, private dynamicDialogRef: DynamicDialogRef, private router: Router) {
this.searchText = dynamicDialogConfig.data.bookTitle;
this.bookId = this.dynamicDialogConfig.data.bookId;
this.libraryId = this.dynamicDialogConfig.data.libraryId;
diff --git a/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.html b/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.html
index e3fbfae63..c27396e39 100644
--- a/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.html
+++ b/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.html
@@ -17,7 +17,7 @@
{{ book.metadata.title }}
{{ getAuthorNames(book) }}
-
+
diff --git a/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts b/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts
index f9211944e..213940ff9 100644
--- a/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts
+++ b/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts
@@ -1,6 +1,6 @@
import {Component, OnInit, ViewChild, ElementRef, Input, computed, signal} from '@angular/core';
import {Book} from '../../model/book.model';
-import {BookService} from '../../service/book.service';
+import {LibraryAndBookService} from '../../service/library-and-book.service';
import {Button} from 'primeng/button';
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
import {NgForOf, NgIf} from '@angular/common';
@@ -27,7 +27,7 @@ export class DashboardScrollerComponent implements OnInit {
return this.bookListType === 'lastRead' ? this.bookService.lastReadBooks() : this.bookService.latestAddedBooks();
});
- constructor(private bookService: BookService, private router: Router) {
+ constructor(private bookService: LibraryAndBookService, private router: Router) {
}
ngOnInit(): void {
@@ -50,9 +50,8 @@ export class DashboardScrollerComponent implements OnInit {
return book.metadata.authors?.map((author) => author.name).join(', ') || 'No authors available';
}
- openBook(bookId: number): void {
- const url = `/pdf-viewer/book/${bookId}`;
- window.open(url, '_blank');
+ openBook(book: Book): void {
+ this.bookService.readBook(book);
}
openBookInfo(bookId: number, libraryId: number) {
diff --git a/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts b/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts
index 0cfce00df..a509ce276 100644
--- a/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts
+++ b/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts
@@ -1,11 +1,11 @@
-import {Component, Signal, WritableSignal} from '@angular/core';
-import { LibraryService } from '../../service/library.service';
-import { Library } from '../../model/library.model';
-import { Button } from 'primeng/button';
-import { NgIf } from '@angular/common';
-import { LibraryCreatorComponent } from '../library-creator/library-creator.component';
-import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
+import {Component, Signal} from '@angular/core';
+import {Library} from '../../model/library.model';
+import {Button} from 'primeng/button';
+import {NgIf} from '@angular/common';
+import {LibraryCreatorComponent} from '../library-creator/library-creator.component';
+import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroller.component';
+import {LibraryAndBookService} from '../../service/library-and-book.service';
@Component({
selector: 'app-home-page',
@@ -22,8 +22,8 @@ export class DashboardComponent {
private libraries: Signal;
ref: DynamicDialogRef | undefined;
- constructor(private libraryService: LibraryService, public dialogService: DialogService) {
- this.libraries = this.libraryService.libraries;
+ constructor(private libraryBookService: LibraryAndBookService, public dialogService: DialogService) {
+ this.libraries = this.libraryBookService.libraries;
}
get isLibrariesEmpty(): boolean {
diff --git a/booklore-ui/src/app/book/component/file-upload/file-upload.component.ts b/booklore-ui/src/app/book/component/file-upload/file-upload.component.ts
index 2fe77307f..31cd3f243 100644
--- a/booklore-ui/src/app/book/component/file-upload/file-upload.component.ts
+++ b/booklore-ui/src/app/book/component/file-upload/file-upload.component.ts
@@ -1,6 +1,5 @@
-import {Component, OnInit, Signal, WritableSignal} from '@angular/core';
+import {Component, Signal} from '@angular/core';
import {Library} from '../../model/library.model';
-import {LibraryService} from '../../service/library.service';
import {FileUploadService} from '../../../file-upload.service';
import {Button} from 'primeng/button';
import {NgIf} from '@angular/common';
@@ -8,6 +7,7 @@ import {DropdownModule} from 'primeng/dropdown';
import {FormsModule} from '@angular/forms';
import {ToastService} from '../../../toast.service';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
+import {LibraryAndBookService} from '../../service/library-and-book.service';
@Component({
selector: 'app-file-upload-v2',
@@ -29,11 +29,11 @@ export class FileUploadComponent {
errorMessage: string | null = null;
constructor(
- private libraryService: LibraryService,
+ private libraryBookService: LibraryAndBookService,
private fileUploadService: FileUploadService,
private toastService: ToastService,
private dynamicDialogRef: DynamicDialogRef) {
- this.libraries = this.libraryService.libraries;
+ this.libraries = this.libraryBookService.libraries;
}
triggerFileInput(fileInput: HTMLInputElement): void {
diff --git a/booklore-ui/src/app/book/component/layout/app.menu.component.ts b/booklore-ui/src/app/book/component/layout/app.menu.component.ts
index 3b71b2af8..efe2c125e 100644
--- a/booklore-ui/src/app/book/component/layout/app.menu.component.ts
+++ b/booklore-ui/src/app/book/component/layout/app.menu.component.ts
@@ -1,9 +1,8 @@
-import {Component, computed, OnInit, Signal, WritableSignal} from '@angular/core';
+import {Component, computed, OnInit} from '@angular/core';
import {AppMenuitemComponent} from './app.menuitem.component';
import {NgForOf, NgIf} from '@angular/common';
import {MenuModule} from 'primeng/menu';
-import {LibraryService} from '../../service/library.service';
-import {Library} from '../../model/library.model';
+import {LibraryAndBookService} from '../../service/library-and-book.service';
@Component({
selector: 'app-menu',
@@ -14,7 +13,7 @@ export class AppMenuComponent implements OnInit {
home: any[] = [];
libraryMenu = computed(() => {
- const libraries = this.libraryService.libraries();
+ const libraries = this.libraryBookService.libraries();
return [
{
label: 'Library',
@@ -28,7 +27,7 @@ export class AppMenuComponent implements OnInit {
];
});
- constructor(private libraryService: LibraryService) {
+ constructor(private libraryBookService: LibraryAndBookService) {
}
diff --git a/booklore-ui/src/app/book/component/library-browser/library-browser.component.html b/booklore-ui/src/app/book/component/library-browser/library-browser.component.html
index 005fad155..47494eef7 100644
--- a/booklore-ui/src/app/book/component/library-browser/library-browser.component.html
+++ b/booklore-ui/src/app/book/component/library-browser/library-browser.component.html
@@ -1,31 +1,40 @@
-