Add sequential next/previous book navigation from library, filtered, and search views (#1931)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -50,6 +50,7 @@ import {GroupRule} from '../../../magic-shelf/component/magic-shelf-component';
|
||||
import {TaskHelperService} from '../../../settings/task-management/task-helper.service';
|
||||
import {FilterLabelHelper} from './filter-label.helper';
|
||||
import {LoadingService} from '../../../../core/services/loading.service';
|
||||
import {BookNavigationService} from '../../service/book-navigation.service';
|
||||
|
||||
export enum EntityType {
|
||||
LIBRARY = 'Library',
|
||||
@@ -118,10 +119,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
protected confirmationService = inject(ConfirmationService);
|
||||
protected magicShelfService = inject(MagicShelfService);
|
||||
protected bookRuleEvaluatorService = inject(BookRuleEvaluatorService);
|
||||
protected taskHelperService = inject(TaskHelperService);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private loadingService = inject(LoadingService);
|
||||
|
||||
protected taskHelperService = inject(TaskHelperService);
|
||||
private bookNavigationService = inject(BookNavigationService);
|
||||
|
||||
bookState$: Observable<BookState> | undefined;
|
||||
entity$: Observable<Library | Shelf | MagicShelf | null> | undefined;
|
||||
@@ -584,6 +585,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
)
|
||||
.subscribe(books => {
|
||||
this.currentBooks = books;
|
||||
this.bookNavigationService.setAvailableBookIds(books.map(book => book.id));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -22,6 +22,7 @@ import {ResetProgressTypes} from '../../../../../shared/constants/reset-progress
|
||||
import {ReadStatusHelper} from '../../../helpers/read-status.helper';
|
||||
import {BookDialogHelperService} from '../BookDialogHelperService';
|
||||
import {TaskHelperService} from '../../../../settings/task-management/task-helper.service';
|
||||
import {BookNavigationService} from '../../../service/book-navigation.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card',
|
||||
@@ -61,6 +62,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private bookDialogHelperService = inject(BookDialogHelperService);
|
||||
private bookNavigationService = inject(BookNavigationService);
|
||||
|
||||
private userPermissions: any;
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
@@ -110,7 +112,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
|
||||
get displayTitle(): string | undefined {
|
||||
return (this.isSeriesCollapsed && this.book.metadata?.seriesName) ? this.book.metadata?.seriesName : this.book.metadata?.title;
|
||||
// return (this.isSeriesCollapsed && this.book.metadata?.seriesName) ? this.book.metadata.seriesName : this.book.metadata?.title;
|
||||
}
|
||||
|
||||
onImageLoad(): void {
|
||||
@@ -132,7 +133,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
onMenuToggle(event: Event, menu: TieredMenu): void {
|
||||
menu.toggle(event);
|
||||
|
||||
// Load additional files if not already loaded and needed
|
||||
if (!this.additionalFilesLoaded && !this.isSubMenuLoading && this.needsAdditionalFilesData()) {
|
||||
this.isSubMenuLoading = true;
|
||||
this.bookService.getBookByIdFromAPI(this.book.id, true).subscribe({
|
||||
@@ -446,6 +446,11 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
}
|
||||
|
||||
openBookInfo(book: Book): void {
|
||||
const allBookIds = this.bookNavigationService.getAvailableBookIds();
|
||||
if (allBookIds.length > 0) {
|
||||
this.bookNavigationService.setNavigationContext(allBookIds, book.id);
|
||||
}
|
||||
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
|
||||
export interface BookNavigationState {
|
||||
bookIds: number[];
|
||||
currentIndex: number;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BookNavigationService {
|
||||
private navigationState$ = new BehaviorSubject<BookNavigationState | null>(null);
|
||||
private availableBookIds: number[] = [];
|
||||
|
||||
setAvailableBookIds(bookIds: number[]): void {
|
||||
this.availableBookIds = bookIds;
|
||||
}
|
||||
|
||||
getAvailableBookIds(): number[] {
|
||||
return this.availableBookIds;
|
||||
}
|
||||
|
||||
setNavigationContext(bookIds: number[], currentBookId: number): void {
|
||||
const currentIndex = bookIds.indexOf(currentBookId);
|
||||
if (currentIndex !== -1) {
|
||||
this.navigationState$.next({bookIds, currentIndex});
|
||||
} else {
|
||||
this.navigationState$.next(null);
|
||||
}
|
||||
}
|
||||
|
||||
getNavigationState(): Observable<BookNavigationState | null> {
|
||||
return this.navigationState$.asObservable();
|
||||
}
|
||||
|
||||
canNavigatePrevious(): boolean {
|
||||
const state = this.navigationState$.value;
|
||||
return state !== null && state.currentIndex > 0;
|
||||
}
|
||||
|
||||
canNavigateNext(): boolean {
|
||||
const state = this.navigationState$.value;
|
||||
return state !== null && state.currentIndex < state.bookIds.length - 1;
|
||||
}
|
||||
|
||||
getPreviousBookId(): number | null {
|
||||
const state = this.navigationState$.value;
|
||||
if (state && state.currentIndex > 0) {
|
||||
return state.bookIds[state.currentIndex - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getNextBookId(): number | null {
|
||||
const state = this.navigationState$.value;
|
||||
if (state && state.currentIndex < state.bookIds.length - 1) {
|
||||
return state.bookIds[state.currentIndex + 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
updateCurrentBook(bookId: number): void {
|
||||
const state = this.navigationState$.value;
|
||||
if (state) {
|
||||
const newIndex = state.bookIds.indexOf(bookId);
|
||||
if (newIndex !== -1) {
|
||||
this.navigationState$.next({
|
||||
...state,
|
||||
currentIndex: newIndex
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentPosition(): { current: number; total: number } | null {
|
||||
const state = this.navigationState$.value;
|
||||
if (state) {
|
||||
return {
|
||||
current: state.currentIndex + 1,
|
||||
total: state.bookIds.length
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user