Introduce reading session tracking with visual insights (#1957)
* Introduce reading session tracking with visual insights (#1957) --------- Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -97,6 +97,9 @@
|
||||
<button class="view-button background-toggle" (click)="toggleBackground()" title="Toggle Background Color">
|
||||
<span>{{ backgroundColorIcon }}</span>
|
||||
</button>
|
||||
<button class="view-button close-button" (click)="closeReader()" title="Close Reader">
|
||||
<span>✕</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="mobile-controls">
|
||||
@@ -160,6 +163,10 @@
|
||||
<span class="option-icon">{{ backgroundColorIcon }}</span>
|
||||
<span class="option-label">Background</span>
|
||||
</button>
|
||||
<button class="mobile-option" (click)="closeReader()">
|
||||
<span class="option-icon">✕</span>
|
||||
<span class="option-label">Close Reader</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -311,6 +311,18 @@
|
||||
background: #4a4a4a;
|
||||
border-color: #666;
|
||||
}
|
||||
|
||||
&.close-button {
|
||||
span {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: rgba(239, 68, 68, 0.2);
|
||||
border-color: rgba(239, 68, 68, 0.4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.fit-mode-dropdown {
|
||||
@@ -387,11 +399,11 @@
|
||||
background: #0f0f0f;
|
||||
min-height: 0;
|
||||
position: relative;
|
||||
|
||||
|
||||
&:not(.two-page-view):not(.infinite-scroll) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
|
||||
.pages-wrapper {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
@@ -399,7 +411,7 @@
|
||||
align-items: center;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
|
||||
.end-of-comic-action {
|
||||
flex: 0 0 auto;
|
||||
margin-top: 1rem;
|
||||
@@ -777,7 +789,7 @@
|
||||
|
||||
.action-icon { font-size: 2rem; }
|
||||
.action-text { font-size: 1rem; }
|
||||
.book-title {
|
||||
.book-title {
|
||||
font-size: 0.85rem;
|
||||
max-width: 250px;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {Component, HostListener, inject, OnInit} from '@angular/core';
|
||||
import {Component, HostListener, inject, OnInit, OnDestroy} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {CommonModule, Location} from '@angular/common';
|
||||
import {PageTitleService} from "../../../shared/service/page-title.service";
|
||||
import {CbxReaderService} from '../../book/service/cbx-reader.service';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
@@ -21,6 +22,7 @@ import {BookState} from '../../book/model/state/book-state.model';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {NewPdfReaderService} from '../../book/service/new-pdf-reader.service';
|
||||
import {ReadingSessionService} from '../../../shared/service/reading-session.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -30,7 +32,7 @@ import {NewPdfReaderService} from '../../book/service/new-pdf-reader.service';
|
||||
templateUrl: './cbx-reader.component.html',
|
||||
styleUrl: './cbx-reader.component.scss'
|
||||
})
|
||||
export class CbxReaderComponent implements OnInit {
|
||||
export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
bookType!: BookType;
|
||||
|
||||
goToPageInput: number | null = null;
|
||||
@@ -53,12 +55,14 @@ export class CbxReaderComponent implements OnInit {
|
||||
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private location = inject(Location);
|
||||
private cbxReaderService = inject(CbxReaderService);
|
||||
private pdfReaderService = inject(NewPdfReaderService);
|
||||
private bookService = inject(BookService);
|
||||
private userService = inject(UserService);
|
||||
private messageService = inject(MessageService);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private readingSessionService = inject(ReadingSessionService);
|
||||
|
||||
|
||||
showFitModeDropdown: boolean = false;
|
||||
@@ -164,6 +168,9 @@ export class CbxReaderComponent implements OnInit {
|
||||
}
|
||||
this.alignCurrentPageToParity();
|
||||
this.isLoading = false;
|
||||
|
||||
const percentage = this.pages.length > 0 ? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10 : 0;
|
||||
this.readingSessionService.startSession(this.bookId, "CBX", (this.currentPage + 1).toString(), percentage);
|
||||
},
|
||||
error: (err) => {
|
||||
const errorMessage = err?.error?.message || 'Failed to load pages';
|
||||
@@ -253,6 +260,7 @@ export class CbxReaderComponent implements OnInit {
|
||||
this.currentPage++;
|
||||
this.scrollToPage(this.currentPage);
|
||||
this.updateProgress();
|
||||
this.updateSessionProgress();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -269,6 +277,7 @@ export class CbxReaderComponent implements OnInit {
|
||||
|
||||
if (this.currentPage !== previousPage) {
|
||||
this.updateProgress();
|
||||
this.updateSessionProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,6 +287,7 @@ export class CbxReaderComponent implements OnInit {
|
||||
this.currentPage--;
|
||||
this.scrollToPage(this.currentPage);
|
||||
this.updateProgress();
|
||||
this.updateSessionProgress();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -288,6 +298,7 @@ export class CbxReaderComponent implements OnInit {
|
||||
this.currentPage = Math.max(0, this.currentPage - 1);
|
||||
}
|
||||
this.updateProgress();
|
||||
this.updateSessionProgress();
|
||||
}
|
||||
|
||||
private alignCurrentPageToParity() {
|
||||
@@ -420,6 +431,7 @@ export class CbxReaderComponent implements OnInit {
|
||||
if (newPage !== this.currentPage) {
|
||||
this.currentPage = newPage;
|
||||
this.updateProgress();
|
||||
this.updateSessionProgress();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -483,6 +495,16 @@ export class CbxReaderComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
private updateSessionProgress(): void {
|
||||
const percentage = this.pages.length > 0
|
||||
? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10
|
||||
: 0;
|
||||
this.readingSessionService.updateProgress(
|
||||
(this.currentPage + 1).toString(),
|
||||
percentage
|
||||
);
|
||||
}
|
||||
|
||||
goToPage(page: number): void {
|
||||
if (page < 1 || page > this.pages.length) return;
|
||||
|
||||
@@ -495,9 +517,11 @@ export class CbxReaderComponent implements OnInit {
|
||||
this.ensurePageLoaded(targetIndex);
|
||||
this.scrollToPage(targetIndex);
|
||||
this.updateProgress();
|
||||
this.updateSessionProgress();
|
||||
} else {
|
||||
this.alignCurrentPageToParity();
|
||||
this.updateProgress();
|
||||
this.updateSessionProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,12 +610,14 @@ export class CbxReaderComponent implements OnInit {
|
||||
|
||||
navigateToPreviousBook(): void {
|
||||
if (this.previousBookInSeries) {
|
||||
this.endReadingSession();
|
||||
this.router.navigate(['/cbx-reader/book', this.previousBookInSeries.id]);
|
||||
}
|
||||
}
|
||||
|
||||
navigateToNextBook(): void {
|
||||
if (this.nextBookInSeries) {
|
||||
this.endReadingSession();
|
||||
this.router.navigate(['/cbx-reader/book', this.nextBookInSeries.id]);
|
||||
}
|
||||
}
|
||||
@@ -672,4 +698,20 @@ export class CbxReaderComponent implements OnInit {
|
||||
if (!this.nextBookInSeries) return 'No Next Book';
|
||||
return `Next Book: ${this.getBookDisplayTitle(this.nextBookInSeries)}`;
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.endReadingSession();
|
||||
}
|
||||
|
||||
private endReadingSession(): void {
|
||||
if (this.readingSessionService.isSessionActive()) {
|
||||
const percentage = this.pages.length > 0 ? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10 : 0;
|
||||
this.readingSessionService.endSession((this.currentPage + 1).toString(), percentage);
|
||||
}
|
||||
}
|
||||
|
||||
closeReader(): void {
|
||||
this.endReadingSession();
|
||||
this.location.back();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user