feat: add support for personal book ratings
- Introduced 'personalRating' field in book metadata - Added UI for 10-star rating input - Persist personal ratings via updateBookMetadata API - Updated filters and sorting to include personal rating range
This commit is contained in:
committed by
Aditya Chandel
parent
ce96fcff6d
commit
cd4e14c8ad
+31
-13
@@ -3,10 +3,24 @@ import {ActivatedRoute} from '@angular/router';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {Book, BookRecommendation} from '../../model/book.model';
|
||||
import {Observable, Subscription} from 'rxjs';
|
||||
import {distinctUntilChanged, filter, map, shareReplay, switchMap, take, tap} from 'rxjs/operators';
|
||||
import {
|
||||
distinctUntilChanged,
|
||||
filter,
|
||||
map,
|
||||
shareReplay,
|
||||
switchMap,
|
||||
take,
|
||||
tap
|
||||
} from 'rxjs/operators';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {
|
||||
Tab,
|
||||
TabList,
|
||||
TabPanel,
|
||||
TabPanels,
|
||||
Tabs
|
||||
} from 'primeng/tabs';
|
||||
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
||||
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
||||
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
||||
@@ -40,34 +54,36 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
admin: boolean = false;
|
||||
|
||||
private userSubscription: Subscription = Subscription.EMPTY;
|
||||
private routeSubscription: Subscription = Subscription.EMPTY;
|
||||
private tabSubscription: Subscription = Subscription.EMPTY;
|
||||
private recommendationSubscription: Subscription = Subscription.EMPTY;
|
||||
private appSettings$ = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.loadBooks();
|
||||
|
||||
this.book$ = this.route.paramMap.pipe(
|
||||
const bookId$ = this.route.paramMap.pipe(
|
||||
map(params => Number(params.get('bookId'))),
|
||||
filter(bookId => !isNaN(bookId)),
|
||||
distinctUntilChanged(),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
this.book$ = bookId$.pipe(
|
||||
switchMap(bookId =>
|
||||
this.bookService.bookState$.pipe(
|
||||
map(state => state.books?.find(b => b.id === bookId)),
|
||||
filter((book): book is Book => !!book && !!book.metadata),
|
||||
distinctUntilChanged((a, b) => a.id === b.id && a.metadata === b.metadata),
|
||||
switchMap(book =>
|
||||
this.bookService.getBookByIdFromAPI(book.id, true).pipe(
|
||||
tap(bookWithDescription => {
|
||||
this.fetchBookRecommendationsIfNeeded(bookWithDescription.metadata!.bookId);
|
||||
})
|
||||
)
|
||||
)
|
||||
switchMap(book => this.bookService.getBookByIdFromAPI(book.id, true))
|
||||
)
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
this.recommendationSubscription = bookId$.pipe(
|
||||
tap(bookId => this.fetchBookRecommendationsIfNeeded(bookId))
|
||||
).subscribe();
|
||||
|
||||
this.tabSubscription = this.route.queryParamMap.pipe(
|
||||
map(queryParams => queryParams.get('tab') ?? 'view'),
|
||||
distinctUntilChanged()
|
||||
@@ -85,8 +101,8 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.userSubscription.unsubscribe();
|
||||
this.routeSubscription.unsubscribe();
|
||||
this.tabSubscription.unsubscribe();
|
||||
this.recommendationSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
private fetchBookRecommendationsIfNeeded(bookId: number): void {
|
||||
@@ -98,7 +114,9 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
.subscribe(settings => {
|
||||
if (settings!.similarBookRecommendation ?? false) {
|
||||
this.bookService.getBookRecommendations(bookId).subscribe(recommendations => {
|
||||
this.recommendedBooks = recommendations;
|
||||
this.recommendedBooks = recommendations.sort(
|
||||
(a, b) => (b.similarityScore ?? 0) - (a.similarityScore ?? 0)
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user