- Refactor to remove BookMetadataBI
- Use inject everywhere instead of constructor injection
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable, of} from 'rxjs';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {catchError, map, switchMap, tap} from 'rxjs/operators';
|
||||
@@ -18,7 +18,9 @@ export class BookService {
|
||||
});
|
||||
bookState$ = this.bookStateSubject.asObservable();
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
private http = inject(HttpClient);
|
||||
|
||||
constructor() {
|
||||
this.loadBooks();
|
||||
}
|
||||
|
||||
@@ -113,21 +115,26 @@ export class BookService {
|
||||
);
|
||||
}
|
||||
|
||||
readBook(book: Book): void {
|
||||
if (book.bookType === "PDF") {
|
||||
const url = `/pdf-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
this.updateLastReadTime(book.id).subscribe({
|
||||
next: () => console.log('Last read time updated successfully'),
|
||||
error: err => console.error('Failed to update last read time', err),
|
||||
});
|
||||
} else if (book.bookType === "EPUB") {
|
||||
const url = `/epub-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
console.error('Unsupported book type:', book.bookType);
|
||||
return;
|
||||
}
|
||||
readBook(bookId: number): void {
|
||||
this.getBookById(bookId).subscribe((book) => {
|
||||
if (book) {
|
||||
if (book.bookType === "PDF") {
|
||||
const url = `/pdf-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
this.updateLastReadTime(book.id).subscribe({
|
||||
next: () => console.log('Last read time updated successfully'),
|
||||
error: err => console.error('Failed to update last read time', err),
|
||||
});
|
||||
} else if (book.bookType === "EPUB") {
|
||||
const url = `/epub-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
console.error('Unsupported book type:', book.bookType);
|
||||
}
|
||||
} else {
|
||||
console.error('Book not found');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
searchBooks(query: string): Observable<Book[]> {
|
||||
@@ -145,7 +152,7 @@ export class BookService {
|
||||
|
||||
getBookData(bookId: number): Observable<Blob> {
|
||||
console.log('Fetching book data...');
|
||||
return this.http.get<Blob>(`${this.url}/${bookId}/data`, { responseType: 'blob' as 'json' });
|
||||
return this.http.get<Blob>(`${this.url}/${bookId}/data`, {responseType: 'blob' as 'json'});
|
||||
}
|
||||
|
||||
getBookCoverUrl(bookId: number): string {
|
||||
@@ -161,7 +168,7 @@ export class BookService {
|
||||
}
|
||||
|
||||
saveEpubProgress(bookId: number, progress: string): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/progress`, { bookId: bookId, epubProgress: progress });
|
||||
return this.http.post<void>(`${this.url}/progress`, {bookId: bookId, epubProgress: progress});
|
||||
}
|
||||
|
||||
/*------------------ All the websocket handlers go below ------------------*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
||||
import {Router} from '@angular/router';
|
||||
import {LibraryService} from './library.service';
|
||||
@@ -13,15 +13,14 @@ import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class LibraryShelfMenuService {
|
||||
constructor(
|
||||
private confirmationService: ConfirmationService,
|
||||
private messageService: MessageService,
|
||||
private libraryService: LibraryService,
|
||||
private shelfService: ShelfService,
|
||||
private router: Router,
|
||||
private dialogService: DialogService
|
||||
) {
|
||||
}
|
||||
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private shelfService = inject(ShelfService);
|
||||
private router = inject(Router);
|
||||
private dialogService = inject(DialogService);
|
||||
|
||||
|
||||
initializeLibraryMenuItems(entity: Library | Shelf | null): MenuItem[] {
|
||||
return [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable, of, tap} from 'rxjs';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {catchError, map} from 'rxjs/operators';
|
||||
@@ -20,7 +20,10 @@ export class LibraryService {
|
||||
});
|
||||
libraryState$ = this.libraryStateSubject.asObservable();
|
||||
|
||||
constructor(private http: HttpClient, private bookService: BookService) {
|
||||
private http = inject(HttpClient);
|
||||
private bookService = inject(BookService);
|
||||
|
||||
constructor() {
|
||||
this.loadLibraries();
|
||||
}
|
||||
|
||||
@@ -48,12 +51,12 @@ export class LibraryService {
|
||||
map(createdLibrary => {
|
||||
const currentState = this.libraryStateSubject.value;
|
||||
const updatedLibraries = currentState.libraries ? [...currentState.libraries, createdLibrary] : [createdLibrary];
|
||||
this.libraryStateSubject.next({ ...currentState, libraries: updatedLibraries });
|
||||
this.libraryStateSubject.next({...currentState, libraries: updatedLibraries});
|
||||
return createdLibrary;
|
||||
}),
|
||||
catchError(error => {
|
||||
const currentState = this.libraryStateSubject.value;
|
||||
this.libraryStateSubject.next({ ...currentState, error: error.message });
|
||||
this.libraryStateSubject.next({...currentState, error: error.message});
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
@@ -65,11 +68,11 @@ export class LibraryService {
|
||||
this.bookService.removeBooksByLibraryId(libraryId);
|
||||
const currentState = this.libraryStateSubject.value;
|
||||
const updatedLibraries = currentState.libraries?.filter(library => library.id !== libraryId) || [];
|
||||
this.libraryStateSubject.next({ ...currentState, libraries: updatedLibraries });
|
||||
this.libraryStateSubject.next({...currentState, libraries: updatedLibraries});
|
||||
}),
|
||||
catchError(error => {
|
||||
const currentState = this.libraryStateSubject.value;
|
||||
this.libraryStateSubject.next({ ...currentState, error: error.message });
|
||||
this.libraryStateSubject.next({...currentState, error: error.message});
|
||||
return of();
|
||||
})
|
||||
);
|
||||
@@ -79,7 +82,7 @@ export class LibraryService {
|
||||
return this.http.put<void>(`${this.url}/${libraryId}/refresh`, {}).pipe(
|
||||
catchError(error => {
|
||||
const currentState = this.libraryStateSubject.value;
|
||||
this.libraryStateSubject.next({ ...currentState, error: error.message });
|
||||
this.libraryStateSubject.next({...currentState, error: error.message});
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
@@ -92,12 +95,12 @@ export class LibraryService {
|
||||
const updatedLibraries = currentState.libraries?.map(library =>
|
||||
library.id === libraryId ? updatedLibrary : library
|
||||
) || [];
|
||||
this.libraryStateSubject.next({ ...currentState, libraries: updatedLibraries });
|
||||
this.libraryStateSubject.next({...currentState, libraries: updatedLibraries});
|
||||
return updatedLibrary;
|
||||
}),
|
||||
catchError(error => {
|
||||
const currentState = this.libraryStateSubject.value;
|
||||
this.libraryStateSubject.next({ ...currentState, error: error.message });
|
||||
this.libraryStateSubject.next({...currentState, error: error.message});
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import { BehaviorSubject, Observable, of, tap } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
@@ -19,9 +19,8 @@ export class ShelfService {
|
||||
});
|
||||
shelfState$ = this.shelfStateSubject.asObservable();
|
||||
|
||||
constructor(private http: HttpClient, private bookService: BookService) {
|
||||
this.loadShelves();
|
||||
}
|
||||
private http = inject(HttpClient);
|
||||
private bookService = inject(BookService);
|
||||
|
||||
private loadShelves(): void {
|
||||
this.http.get<Shelf[]>(this.url).pipe(
|
||||
|
||||
Reference in New Issue
Block a user