Add theme switching
More reactivity in Library Browser
This commit is contained in:
-10
@@ -1,10 +0,0 @@
|
||||
package com.adityachandel.booklore.model.dto.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ApiResponseMessage {
|
||||
private String message;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {LibraryService} from './book/service/library.service';
|
||||
|
||||
@Component({
|
||||
@@ -7,7 +7,11 @@ import {LibraryService} from './book/service/library.service';
|
||||
standalone: false,
|
||||
styleUrl: './app.component.scss'
|
||||
})
|
||||
export class AppComponent {
|
||||
constructor(private libraryService: LibraryService) {
|
||||
export class AppComponent implements OnInit {
|
||||
|
||||
constructor(private libraryService: LibraryService) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryService.initializeLibraries();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
<div class="book-metadata">
|
||||
<div class="book-header">
|
||||
<div class="cover-container">
|
||||
<img [src]="coverImageSrc(book?.id)" class="book-cover placeholder" alt="Cover of {{ book?.metadata?.title }}" loading="lazy"/>
|
||||
<div class="cover-wrapper">
|
||||
<img [src]="coverImageSrc(book?.id)" class="book-cover placeholder" alt="Cover of {{ book?.metadata?.title }}" loading="lazy"/>
|
||||
<div class="overlay" (click)="readBook(book?.id)">
|
||||
<p-button icon="pi pi-book" [rounded]="true"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="book-navigation">
|
||||
<p-button
|
||||
|
||||
@@ -17,14 +17,36 @@
|
||||
}
|
||||
|
||||
.cover-container {
|
||||
position: relative;
|
||||
max-width: 200px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.cover-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||
transition: filter 0.3s ease;
|
||||
}
|
||||
|
||||
.cover-container:hover .book-cover {
|
||||
filter: blur(2px);
|
||||
}
|
||||
|
||||
.overlay {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cover-container:hover .overlay {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.metadata {
|
||||
|
||||
@@ -36,7 +36,7 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.routeSubscription = this.activatedRoute.paramMap.subscribe((paramMap) => {
|
||||
const bookId = +paramMap.get('bookId')!;
|
||||
const bookId = +paramMap.get('bookId')!;
|
||||
const libraryId = +paramMap.get('libraryId')!;
|
||||
if (bookId && libraryId) {
|
||||
this.loadBookWithNeighbors(bookId, libraryId);
|
||||
|
||||
+4
-6
@@ -20,8 +20,8 @@
|
||||
<div *ngFor="let metadata of bookMetadataList" class="book-metadata">
|
||||
<div class="metadata-header">
|
||||
<div class="book-image-container">
|
||||
<img class="book-image" src="{{ metadata.thumbnail }}" alt="Book Cover"/>
|
||||
<p-button class="select-button" (click)="selectMetadata(metadata)">Select</p-button>
|
||||
<img class="book-image" [src]="metadata.thumbnail || 'assets/book-cover-metadata.png'" alt="Book Cover"/>
|
||||
<p-button class="select-button" (click)="selectMetadata(metadata)">Select</p-button>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ metadata.title }}<span *ngIf="metadata.subtitle">: {{ metadata.subtitle }}</span></h3>
|
||||
@@ -32,10 +32,8 @@
|
||||
<p><strong>Description:</strong> {{ truncateDescription(metadata.description) }}</p>
|
||||
<p><strong>Page Count:</strong> {{ metadata.pageCount }}</p>
|
||||
<p *ngIf="metadata.googleBookId">
|
||||
<strong>Google Book Id:</strong>
|
||||
<a [href]="'https://books.google.com/books?id=' + metadata.googleBookId" target="_blank">
|
||||
{{ metadata.googleBookId }}
|
||||
</a>
|
||||
<strong>Google Book Id: </strong>
|
||||
<a [href]="'https://books.google.com/books?id=' + metadata.googleBookId" target="_blank">{{ metadata.googleBookId }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
|
||||
import {BookMetadata} from '../../model/book.model';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
import {FormBuilder, FormsModule} from '@angular/forms';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Router} from '@angular/router';
|
||||
import {Button} from 'primeng/button';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, WritableSignal } from '@angular/core';
|
||||
import {Component, Signal, WritableSignal} from '@angular/core';
|
||||
import { LibraryService } from '../../service/library.service';
|
||||
import { Library } from '../../model/library.model';
|
||||
import { Button } from 'primeng/button';
|
||||
@@ -19,7 +19,7 @@ import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroll
|
||||
providers: [DialogService],
|
||||
})
|
||||
export class DashboardComponent {
|
||||
private libraries: WritableSignal<Library[]>;
|
||||
private libraries: Signal<Library[]>;
|
||||
ref: DynamicDialogRef | undefined;
|
||||
|
||||
constructor(private libraryService: LibraryService, public dialogService: DialogService) {
|
||||
@@ -32,13 +32,10 @@ export class DashboardComponent {
|
||||
|
||||
createNewLibrary(event: MouseEvent) {
|
||||
const buttonRect = (event.target as HTMLElement).getBoundingClientRect();
|
||||
|
||||
const dialogWidthPercentage = 50;
|
||||
const viewportWidth = window.innerWidth;
|
||||
const dialogWidth = (dialogWidthPercentage / 100) * viewportWidth;
|
||||
|
||||
const leftPosition = buttonRect.left + (buttonRect.width / 2) - (dialogWidth / 2);
|
||||
|
||||
this.ref = this.dialogService.open(LibraryCreatorComponent, {
|
||||
modal: true,
|
||||
width: `${dialogWidthPercentage}%`,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<div class="flex">
|
||||
<p-dropdown
|
||||
[options]="libraries"
|
||||
[options]="libraries()"
|
||||
optionLabel="name"
|
||||
placeholder="Select Library"
|
||||
[(ngModel)]="selectedLibrary">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Component, OnInit, Signal, WritableSignal} from '@angular/core';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {FileUploadService} from '../../../file-upload.service';
|
||||
@@ -20,8 +20,8 @@ import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
FormsModule
|
||||
],
|
||||
})
|
||||
export class FileUploadComponent implements OnInit {
|
||||
libraries: Library[] = [];
|
||||
export class FileUploadComponent {
|
||||
libraries: Signal<Library[]>;
|
||||
selectedLibrary: Library | null = null;
|
||||
selectedPath: string = '';
|
||||
selectedFileName: string = '';
|
||||
@@ -32,12 +32,8 @@ export class FileUploadComponent implements OnInit {
|
||||
private libraryService: LibraryService,
|
||||
private fileUploadService: FileUploadService,
|
||||
private toastService: ToastService,
|
||||
private dynamicDialogRef: DynamicDialogRef
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.libraries = this.libraryService.libraries();
|
||||
private dynamicDialogRef: DynamicDialogRef) {
|
||||
this.libraries = this.libraryService.libraries;
|
||||
}
|
||||
|
||||
triggerFileInput(fileInput: HTMLInputElement): void {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, computed, OnInit} from '@angular/core';
|
||||
import {Component, computed, OnInit, Signal, WritableSignal} from '@angular/core';
|
||||
import {AppMenuitemComponent} from './app.menuitem.component';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
@@ -12,7 +12,7 @@ import {Library} from '../../model/library.model';
|
||||
})
|
||||
export class AppMenuComponent implements OnInit {
|
||||
home: any[] = [];
|
||||
libraries: any;
|
||||
libraries: Signal<Library[]>;
|
||||
|
||||
libraryMenu = computed(() => [
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<div class="layout-topbar">
|
||||
|
||||
<a class="layout-topbar-logo" routerLink="">
|
||||
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg"
|
||||
alt="logo">
|
||||
@@ -9,10 +10,11 @@
|
||||
<i class="pi pi-bars"></i>
|
||||
</button>
|
||||
|
||||
<app-search></app-search>
|
||||
<div>
|
||||
<app-search></app-search>
|
||||
</div>
|
||||
|
||||
<button #topbarmenubutton class="p-link layout-topbar-menu-button layout-topbar-button"
|
||||
(click)="layoutService.showProfileSidebar()">
|
||||
<button #topbarmenubutton class="p-link layout-topbar-menu-button layout-topbar-button" (click)="layoutService.showProfileSidebar()">
|
||||
<i class="pi pi-ellipsis-v"></i>
|
||||
</button>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {LayoutService} from './service/app.layout.service';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {LibraryCreatorComponent} from '../library-creator/library-creator.component';
|
||||
import {ThemeSwitcherComponent} from '../../../theme-switcher/theme-switcher.component';
|
||||
import {ThemeSwitcherComponent} from '../theme-switcher/theme-switcher.component';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
<div class="book-list"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
(scrolled)="loadMore()">
|
||||
<div class="book-item" *ngFor="let book of books">
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover placeholder" alt="Cover of {{ book.metadata.title }}" loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<h4>{{ book.metadata.title }}</h4>
|
||||
<p>{{ getAuthorNames(book) }}</p>
|
||||
<p-button [rounded]="true" icon="pi pi-eye" class="view-btn" (click)="readBook(book.id)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="read-btn" (click)="openBookInfo(book.id, book.libraryId)"></p-button>
|
||||
<div>
|
||||
<div class="library-header">
|
||||
<h3 class="library-name">{{ libraryNameSignal() }}</h3>
|
||||
<div class="library-header-right">
|
||||
<p-dropdown
|
||||
[options]="cities"
|
||||
[(ngModel)]="selectedCity"
|
||||
optionLabel="name"
|
||||
placeholder="Select Sorting" />
|
||||
<div class="zoom-controls">
|
||||
<p-button icon="pi pi-minus" [rounded]="true" [outlined]="true" (click)="decreaseSize()" [disabled]="isDecreaseDisabled()" severity="info"></p-button>
|
||||
<p-button icon="pi pi-plus" [rounded]="true" [outlined]="true" (click)="increaseSize()" [disabled]="isIncreaseDisabled()" severity="info"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="book-list"
|
||||
infiniteScroll
|
||||
[ngClass]="coverSizeClass"
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
(scrolled)="loadMore()">
|
||||
<div class="book-item" *ngFor="let book of books">
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover placeholder" alt="Cover of {{ book.metadata.title }}" loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<h4 class="book-title">{{ book.metadata.title }}</h4>
|
||||
<p class="book-authors">{{ getAuthorNames(book) }}</p>
|
||||
<p-button [rounded]="true" icon="pi pi-eye" class="view-btn" (click)="readBook(book.id)"></p-button>
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="read-btn" (click)="openBookInfo(book.id, book.libraryId)"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,78 +1,94 @@
|
||||
.library-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 15px 15px 10px 17px;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 12px 12px 0 0;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.library-header-right {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
align-items: center;
|
||||
}
|
||||
.library-name {
|
||||
margin: 0;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.zoom-controls {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.book-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
|
||||
grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
|
||||
gap: 20px;
|
||||
transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.small {
|
||||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||||
}
|
||||
|
||||
.medium {
|
||||
grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
|
||||
}
|
||||
|
||||
.large {
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
}
|
||||
|
||||
.extra-large {
|
||||
grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
|
||||
}
|
||||
|
||||
.book-item {
|
||||
color: #fff;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
|
||||
overflow: hidden;
|
||||
transition: transform 0.3s ease-in-out;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
height: auto;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 8px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
height: 225px;
|
||||
object-fit: cover;
|
||||
background-color: #444;
|
||||
transition: background-color 0.3s ease, filter 0.3s ease;
|
||||
position: relative;
|
||||
transition: filter 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.book-item:hover .book-cover {
|
||||
filter: blur(2px);
|
||||
}
|
||||
|
||||
.book-item:hover .book-cover::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.book-info {
|
||||
padding: 10px;
|
||||
padding: 7px 7px 5px;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
flex-grow: 1;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 1rem;
|
||||
.book-title {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
margin-bottom: 5px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 100%;
|
||||
text-align: center;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
p {
|
||||
.book-authors {
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.4;
|
||||
margin-top: 0;
|
||||
margin: 0 auto;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 100%;
|
||||
margin-bottom: auto;
|
||||
}
|
||||
|
||||
.authors {
|
||||
@@ -88,18 +104,19 @@ p {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -20%);
|
||||
transform: translate(-50%, -50%);
|
||||
display: none;
|
||||
margin: -60px 0;
|
||||
margin-top: -40px;
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.book-item:hover .view-btn {
|
||||
.book-item:hover .view-btn,
|
||||
.book-item:hover .read-btn {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.book-item:hover .read-btn {
|
||||
display: block;
|
||||
top: 75%;
|
||||
top: 70%;
|
||||
}
|
||||
|
||||
.infinite-scroll {
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { Component, OnInit, NgZone } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BookProgressService } from '../../service/book-progress-service';
|
||||
import { BookService } from '../../service/book.service';
|
||||
import {Component, computed, NgZone, OnChanges, OnInit, signal} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {BookProgressService} from '../../service/book-progress-service';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Book, BookUpdateEvent} from '../../model/book.model';
|
||||
import { combineLatest } from 'rxjs';
|
||||
import {combineLatest} from 'rxjs';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgForOf} from '@angular/common';
|
||||
import {NgClass, NgForOf} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-browser-v2',
|
||||
@@ -15,20 +18,35 @@ import {NgForOf} from '@angular/common';
|
||||
imports: [
|
||||
InfiniteScrollDirective,
|
||||
Button,
|
||||
NgForOf
|
||||
NgForOf,
|
||||
FormsModule,
|
||||
DropdownModule,
|
||||
NgClass
|
||||
]
|
||||
})
|
||||
export class LibraryBrowserComponent implements OnInit {
|
||||
books: Book[] = [];
|
||||
private libraryId: number = 1;
|
||||
private libraryIdSignal = signal(1);
|
||||
private currentPage: number = 0;
|
||||
cities: any[] | undefined;
|
||||
selectedCity: any;
|
||||
coverSizeClass = 'medium';
|
||||
coverSizeClasses = ['small', 'medium', 'large', 'extra-large'];
|
||||
|
||||
libraryNameSignal = computed(() => {
|
||||
const library = this.libraryService
|
||||
.libraries()
|
||||
.find((library) => library.id === this.libraryIdSignal());
|
||||
return library ? library.name : 'Library not found';
|
||||
});
|
||||
|
||||
constructor(
|
||||
private bookService: BookService,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private router: Router,
|
||||
private bookProgressService: BookProgressService,
|
||||
private ngZone: NgZone
|
||||
private ngZone: NgZone,
|
||||
private libraryService: LibraryService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -36,7 +54,7 @@ export class LibraryBrowserComponent implements OnInit {
|
||||
.subscribe(([params, queryParams]) => {
|
||||
const libraryId = params.get('libraryId');
|
||||
if (libraryId) {
|
||||
this.libraryId = +libraryId;
|
||||
this.libraryIdSignal.set(+libraryId);
|
||||
this.resetState();
|
||||
this.loadBooks();
|
||||
}
|
||||
@@ -48,7 +66,7 @@ export class LibraryBrowserComponent implements OnInit {
|
||||
}
|
||||
|
||||
startListeningForProgress(): void {
|
||||
this.bookProgressService.connect(this.libraryId).subscribe({
|
||||
this.bookProgressService.connect(this.libraryIdSignal()).subscribe({
|
||||
next: (event: BookUpdateEvent) => this.addBookToCollection(event),
|
||||
error: (error) => console.error('Error receiving progress updates:', error),
|
||||
});
|
||||
@@ -72,13 +90,12 @@ export class LibraryBrowserComponent implements OnInit {
|
||||
}
|
||||
|
||||
resetState(): void {
|
||||
console.log("resetState")
|
||||
this.books = [];
|
||||
this.currentPage = 0;
|
||||
}
|
||||
|
||||
loadBooks(): void {
|
||||
this.bookService.loadBooks(this.libraryId, this.currentPage).subscribe({
|
||||
this.bookService.loadBooks(this.libraryIdSignal(), this.currentPage).subscribe({
|
||||
next: (response) => {
|
||||
this.books = [...this.books, ...response.content];
|
||||
this.currentPage++;
|
||||
@@ -107,4 +124,30 @@ export class LibraryBrowserComponent implements OnInit {
|
||||
openBookInfo(bookId: number, libraryId: number) {
|
||||
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
|
||||
}
|
||||
|
||||
getCurrentSizeIndex(): number {
|
||||
return this.coverSizeClasses.indexOf(this.coverSizeClass);
|
||||
}
|
||||
|
||||
increaseSize() {
|
||||
const currentIndex = this.getCurrentSizeIndex();
|
||||
if (currentIndex < this.coverSizeClasses.length - 1) {
|
||||
this.coverSizeClass = this.coverSizeClasses[currentIndex + 1];
|
||||
}
|
||||
}
|
||||
|
||||
decreaseSize() {
|
||||
const currentIndex = this.getCurrentSizeIndex();
|
||||
if (currentIndex > 0) {
|
||||
this.coverSizeClass = this.coverSizeClasses[currentIndex - 1];
|
||||
}
|
||||
}
|
||||
|
||||
isIncreaseDisabled(): boolean {
|
||||
return this.coverSizeClass === this.coverSizeClasses[this.coverSizeClasses.length - 1];
|
||||
}
|
||||
|
||||
isDecreaseDisabled(): boolean {
|
||||
return this.coverSizeClass === this.coverSizeClasses[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export class LibraryCreatorComponent {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
|
||||
validateLibraryNameAndProceed(nextCallback: any) {
|
||||
/*validateLibraryNameAndProceed(nextCallback: any) {
|
||||
if (this.value.trim()) {
|
||||
this.libraryServiceV2.checkLibraryNameExists(this.value).subscribe(
|
||||
(response) => {
|
||||
@@ -95,5 +95,5 @@ export class LibraryCreatorComponent {
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<span class="p-input-icon-left">
|
||||
<i class="pi pi-search"></i>
|
||||
<input
|
||||
style="width: 400px;"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="searchQuery"
|
||||
|
||||
@@ -7,6 +7,7 @@ import { FormsModule } from '@angular/forms';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
import { NgForOf, NgIf } from '@angular/common';
|
||||
import { ButtonDirective } from 'primeng/button';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search',
|
||||
@@ -26,7 +27,7 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||
#searchSubject = new Subject<string>();
|
||||
#subscription!: Subscription;
|
||||
|
||||
constructor(private bookService: BookService) {}
|
||||
constructor(private bookService: BookService, private router: Router) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.initializeSearch();
|
||||
@@ -54,12 +55,13 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||
|
||||
onBookClick(book: Book): void {
|
||||
this.clearSearch();
|
||||
this.openBook(book.id);
|
||||
this.openBook(book.id, book.libraryId);
|
||||
}
|
||||
|
||||
openBook(bookId: number): void {
|
||||
const url = `/pdf-viewer/book/${bookId}`;
|
||||
window.open(url, '_blank');
|
||||
openBook(bookId: number, libraryId: number): void {
|
||||
/*const url = `/pdf-viewer/book/${bookId}`;
|
||||
window.open(url, '_blank');*/
|
||||
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
|
||||
}
|
||||
|
||||
getBookCoverUrl(bookId: number): string {
|
||||
|
||||
@@ -7,7 +7,7 @@ import {HttpClient} from '@angular/common/http';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class BookService {
|
||||
private readonly pageSize = 25;
|
||||
private readonly pageSize = 50;
|
||||
private readonly libraryUrl = 'http://localhost:8080/v1/library';
|
||||
private readonly bookUrl = 'http://localhost:8080/v1/book';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import {computed, Injectable, signal} from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { catchError, map, tap } from 'rxjs/operators';
|
||||
import { Observable, of } from 'rxjs';
|
||||
@@ -10,13 +10,12 @@ import { Library, LibraryApiResponse } from '../model/library.model';
|
||||
export class LibraryService {
|
||||
private libraryUrl: string = 'http://localhost:8080/v1/library';
|
||||
|
||||
libraries = signal<Library[]>([]);
|
||||
#libraries = signal<Library[]>([]);
|
||||
libraries = computed(this.#libraries);
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.getLibrariesFromAPI();
|
||||
}
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getLibrariesFromAPI(): void {
|
||||
initializeLibraries(): void {
|
||||
this.http.get<LibraryApiResponse>(this.libraryUrl).pipe(
|
||||
map(response => response.content),
|
||||
catchError(error => {
|
||||
@@ -25,7 +24,8 @@ export class LibraryService {
|
||||
})
|
||||
).subscribe(
|
||||
(libraries) => {
|
||||
this.libraries.set(libraries);
|
||||
this.#libraries.set(libraries);
|
||||
console.log("Library Initialized")
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -33,7 +33,9 @@ export class LibraryService {
|
||||
createLibrary(newLibrary: Library): Observable<Library> {
|
||||
return this.http.post<Library>(this.libraryUrl, newLibrary).pipe(
|
||||
tap((createdLibrary) => {
|
||||
this.libraries.set([...this.libraries(), createdLibrary]);
|
||||
const currentLibraries = this.#libraries();
|
||||
currentLibraries.push(createdLibrary);
|
||||
this.#libraries.set(currentLibraries);
|
||||
}),
|
||||
catchError(error => {
|
||||
console.error('Error creating library:', error);
|
||||
@@ -42,12 +44,23 @@ export class LibraryService {
|
||||
);
|
||||
}
|
||||
|
||||
checkLibraryNameExists(name: string): Observable<any> {
|
||||
return this.http.get<Library>(`${this.libraryUrl}/search?name=${name}`).pipe(
|
||||
catchError(error => {
|
||||
console.error('Error checking library name:', error);
|
||||
return of(null);
|
||||
getLibraryById(libraryId: number): Library | undefined {
|
||||
return this.#libraries().find(library => library.id === libraryId);
|
||||
}
|
||||
|
||||
/*updateLibrary(id: number, updatedLibrary: Library): Observable<Library> {
|
||||
const url = `${this.libraryUrl}/${id}`;
|
||||
return this.http.put<Library>(url, updatedLibrary).pipe(
|
||||
tap((updatedLibraryFromBackend) => {
|
||||
const updatedLibraries = this._libraries().map((library) =>
|
||||
library.id === id ? { ...library, ...updatedLibraryFromBackend } : library
|
||||
);
|
||||
this._libraries.set(updatedLibraries);
|
||||
}),
|
||||
catchError((error) => {
|
||||
console.error('Error updating library:', error);
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user