- Prevent buttons from overlapping the EPUB content area

- Display chapter name in the header section
This commit is contained in:
adityachandelgit
2025-03-28 10:55:09 -06:00
committed by Aditya Chandel
parent b8947dcf27
commit f31b1b3796
3 changed files with 47 additions and 49 deletions
@@ -2,7 +2,10 @@
<p-progressSpinner *ngIf="isLoading"></p-progressSpinner> <p-progressSpinner *ngIf="isLoading"></p-progressSpinner>
<div *ngIf="!isLoading"> <div *ngIf="!isLoading">
<p-button class="menu-toggle-button" (click)="toggleDrawer()" icon="pi pi-bars" severity="secondary"></p-button> <div class="epub-header">
<div>
<p-button size="small" class="menu-toggle-button" (click)="toggleDrawer()" icon="pi pi-bars" severity="secondary"></p-button>
<p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" header="Chapters"> <p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" header="Chapters">
<ul class="chapter-list"> <ul class="chapter-list">
<li *ngFor="let chapter of chapters" (click)="navigateToChapter(chapter); $event.stopPropagation()" class="chapter-item"> <li *ngFor="let chapter of chapters" (click)="navigateToChapter(chapter); $event.stopPropagation()" class="chapter-item">
@@ -10,12 +13,12 @@
</li> </li>
</ul> </ul>
</p-drawer> </p-drawer>
<div class="epub-header">
<h3>Chapter 1: Introduction | Page 3 of 120</h3>
</div> </div>
<p-button class="settings-toggle-button" (click)="toggleSettingsDrawer()" icon="pi pi-cog" severity="secondary"></p-button> <p>{{ currentChapter }}</p>
<div>
<p-button size="small" class="settings-toggle-button" (click)="toggleSettingsDrawer()" icon="pi pi-cog" severity="secondary"></p-button>
<p-drawer [(visible)]="isSettingsDrawerVisible" [modal]="false" [position]="'right'" header="Settings"> <p-drawer [(visible)]="isSettingsDrawerVisible" [modal]="false" [position]="'right'" header="Settings">
<div class="flex flex-col"> <div class="flex flex-col">
<div class="settings-content"> <div class="settings-content">
@@ -33,10 +36,13 @@
</div> </div>
</div> </div>
</p-drawer> </p-drawer>
</div>
</div>
<div id="epubContainer" #epubContainer></div> <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> <button class="epub-controls-right" (click)="nextPage()">→</button>
</div> </div>
</div> </div>
@@ -1,10 +1,15 @@
.epub-viewer-container { .epub-header {
display: flex; display: flex;
flex-direction: column; flex-direction: row;
justify-content: center;
align-items: center; align-items: center;
justify-content: space-between;
padding-left: 1rem;
padding-right: 1rem;
}
.epub-viewer-container {
overflow: hidden;
height: 100vh; height: 100vh;
position: relative;
} }
#epubContainer { #epubContainer {
@@ -16,7 +21,6 @@
.menu-toggle-button, .menu-toggle-button,
.settings-toggle-button { .settings-toggle-button {
position: absolute;
top: 10px; top: 10px;
z-index: 1000; z-index: 1000;
margin: 0; margin: 0;
@@ -30,16 +34,6 @@
right: 10px; right: 10px;
} }
.epub-header {
position: absolute;
top: 2%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 500;
text-align: center;
color: #333;
}
.epub-controls-left, .epub-controls-left,
.epub-controls-right { .epub-controls-right {
position: absolute; position: absolute;
@@ -35,8 +35,7 @@ export function getCfiFromHref(book: any, href: string): string {
export function getChapter(book: any, location: any) { export function getChapter(book: any, location: any) {
const locationHref = location.start.href; const locationHref = location.start.href;
return flatten(book.navigation.toc)
let match = flatten(book.navigation.toc)
.filter((chapter: any) => { .filter((chapter: any) => {
return book.canonical(chapter.href).includes(book.canonical(locationHref)); return book.canonical(chapter.href).includes(book.canonical(locationHref));
}) })
@@ -44,8 +43,6 @@ export function getChapter(book: any, location: any) {
const locationAfterChapter = EpubCFI.prototype.compare(location.start.cfi, getCfiFromHref(book, chapter.href)) > 0; const locationAfterChapter = EpubCFI.prototype.compare(location.start.cfi, getCfiFromHref(book, chapter.href)) > 0;
return locationAfterChapter ? chapter : result; return locationAfterChapter ? chapter : result;
}, null); }, null);
return match;
} }
@Component({ @Component({
@@ -60,6 +57,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
isLoading = true; isLoading = true;
chapters: { label: string; href: string }[] = []; chapters: { label: string; href: string }[] = [];
currentChapter = '';
isDrawerVisible = false; isDrawerVisible = false;
isSettingsDrawerVisible = false; isSettingsDrawerVisible = false;
private book: any; private book: any;
@@ -263,7 +261,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
if (this.rendition) { if (this.rendition) {
this.rendition.on('relocated', (location: any) => { this.rendition.on('relocated', (location: any) => {
const currentChapter = getChapter(this.book, location); const currentChapter = getChapter(this.book, location);
console.log(currentChapter?.label || 'Unknown Chapter'); this.currentChapter = currentChapter?.label;
this.bookService.saveEpubProgress(this.epub.id, location.start.cfi).subscribe(); this.bookService.saveEpubProgress(this.epub.id, location.start.cfi).subscribe();
}); });
} }