WIP: Checkpoint epub progress
This commit is contained in:
@@ -18,5 +18,7 @@ public class Book {
|
||||
private Instant lastReadTime;
|
||||
private Instant addedOn;
|
||||
private BookMetadata metadata;
|
||||
private Integer pdfProgress;
|
||||
private String epubProgress;
|
||||
private List<Shelf> shelves;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,12 @@ public class BookEntity {
|
||||
@Column(name = "added_on")
|
||||
private Instant addedOn;
|
||||
|
||||
@Column(name = "epub_progress")
|
||||
private String epubProgress;
|
||||
|
||||
@Column(name = "pdf_progress")
|
||||
private Integer pdfProgress;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "book_shelf_mapping",
|
||||
|
||||
@@ -11,11 +11,14 @@ CREATE TABLE IF NOT EXISTS book
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
file_name VARCHAR(255) NOT NULL,
|
||||
book_type VARCHAR(6) NOT NULL,
|
||||
library_id BIGINT NOT NULL,
|
||||
path VARCHAR(1000) NOT NULL,
|
||||
last_read_time TIMESTAMP NULL,
|
||||
added_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
book_type VARCHAR(6) NOT NULL,
|
||||
last_read_time TIMESTAMP NULL,
|
||||
pdf_progress INT NULL,
|
||||
epub_progress VARCHAR(1000) NULL,
|
||||
|
||||
CONSTRAINT fk_library FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE,
|
||||
CONSTRAINT unique_file_library UNIQUE (file_name, library_id),
|
||||
INDEX idx_library_id (library_id),
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface Book {
|
||||
shelves?: Shelf[];
|
||||
lastReadTime?: string;
|
||||
addedOn?: string;
|
||||
epubProgress?: string;
|
||||
pdfProgress?: number;
|
||||
bookType: BookType;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<div class="epub-viewer-container">
|
||||
|
||||
<p-button class="menu-toggle-button" (click)="toggleDrawer()" icon="pi pi-bars"></p-button>
|
||||
|
||||
<p-button class="menu-toggle-button" (click)="toggleDrawer()" icon="pi pi-bars" severity="secondary"></p-button>
|
||||
<p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" header="Chapters">
|
||||
<ul class="chapter-list">
|
||||
<li *ngFor="let chapter of chapters" (click)="navigateToChapter(chapter); $event.stopPropagation()" class="chapter-item">
|
||||
@@ -10,14 +9,14 @@
|
||||
</ul>
|
||||
</p-drawer>
|
||||
|
||||
<p-button class="settings-toggle-button" (click)="toggleSettingsDrawer()" icon="pi pi-cog"></p-button>
|
||||
<p-button class="settings-toggle-button" (click)="toggleSettingsDrawer()" icon="pi pi-cog" severity="secondary"></p-button>
|
||||
<p-drawer [(visible)]="isSettingsDrawerVisible" [modal]="false" [position]="'right'" header="Settings">
|
||||
<div class="flex flex-col">
|
||||
<div class="settings-content">
|
||||
<p>Font Size: {{ fontSize }}%</p>
|
||||
<div class="flex flex-row gap-4">
|
||||
<p-button icon="pi pi-minus" (click)="decreaseFontSize()"></p-button>
|
||||
<p-button icon="pi pi-plus" (click)="increaseFontSize()"></p-button>
|
||||
<p-button icon="pi pi-minus" (click)="decreaseFontSize()" severity="info"></p-button>
|
||||
<p-button icon="pi pi-plus" (click)="increaseFontSize()" severity="info"></p-button>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
<label for="font-type">Font Type:</label>
|
||||
@@ -29,6 +28,6 @@
|
||||
|
||||
<div id="epubContainer" #epubContainer></div>
|
||||
|
||||
<button class="epub-controls-left" (click)="prevPage()">←</button>
|
||||
<button class="epub-controls-left" (click)="prevPage()" >←</button>
|
||||
<button class="epub-controls-right" (click)="nextPage()">→</button>
|
||||
</div>
|
||||
|
||||
@@ -8,19 +8,14 @@ import {FormsModule} from '@angular/forms';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {Book} from '../../book/model/book.model';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-epub-viewer',
|
||||
templateUrl: './epub-viewer.component.html',
|
||||
styleUrls: ['./epub-viewer.component.scss'],
|
||||
imports: [
|
||||
Drawer,
|
||||
Button,
|
||||
NgForOf,
|
||||
FormsModule,
|
||||
Divider,
|
||||
DropdownModule
|
||||
]
|
||||
imports: [Drawer, Button, NgForOf, FormsModule, Divider, DropdownModule]
|
||||
})
|
||||
export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
|
||||
@@ -30,8 +25,10 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
isSettingsDrawerVisible: boolean = false;
|
||||
private book: any;
|
||||
private rendition: any;
|
||||
private keyListener: (e: KeyboardEvent) => void = () => {};
|
||||
private keyListener: (e: KeyboardEvent) => void = () => {
|
||||
};
|
||||
fontSize: number = 120;
|
||||
bookLoreBook: Book | undefined
|
||||
|
||||
fontTypes: any[] = [
|
||||
{label: 'Serif', value: 'serif'},
|
||||
@@ -42,15 +39,22 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
];
|
||||
selectedFontType: string = 'serif';
|
||||
|
||||
constructor(private epubService: EpubService, private route: ActivatedRoute) {
|
||||
constructor(private epubService: EpubService, private route: ActivatedRoute, private bookService: BookService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.paramMap.subscribe((params) => {
|
||||
this.loadBook(+params.get('bookId')!)
|
||||
this.loadEpub(+params.get('bookId')!);
|
||||
});
|
||||
}
|
||||
|
||||
private loadBook(bookId: number): void {
|
||||
this.bookService.getBookById(bookId).subscribe((book) => {
|
||||
this.bookLoreBook = book;
|
||||
});
|
||||
}
|
||||
|
||||
loadEpub(bookId: number): void {
|
||||
this.epubService.downloadEpub(bookId).subscribe(
|
||||
(data: Blob) => {
|
||||
@@ -72,9 +76,16 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
height: '100%',
|
||||
allowScriptedContent: true,
|
||||
});
|
||||
this.rendition.display();
|
||||
|
||||
if(this.bookLoreBook?.epubProgress) {
|
||||
this.rendition.display(this.bookLoreBook?.epubProgress);
|
||||
} else {
|
||||
this.rendition.display();
|
||||
}
|
||||
|
||||
this.setupKeyListener();
|
||||
this.updateFontSize();
|
||||
this.trackProgress();
|
||||
};
|
||||
fileReader.readAsArrayBuffer(data);
|
||||
},
|
||||
@@ -91,6 +102,16 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
document.removeEventListener('keyup', this.keyListener);
|
||||
}
|
||||
|
||||
private trackProgress(): void {
|
||||
if (this.rendition) {
|
||||
this.rendition.on('relocated', (location: any) => {
|
||||
const percentage = location.start.percentage.toFixed(2);
|
||||
console.log(`Reading progress: ${percentage * 100}%`);
|
||||
console.log('Current location:', location);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updateFontSize(): void {
|
||||
if (this.rendition) {
|
||||
this.rendition.themes.fontSize(`${this.fontSize}%`);
|
||||
|
||||
Reference in New Issue
Block a user