feat: initial version of reader

This commit is contained in:
2024-07-06 00:53:46 +03:00
parent 2660aef473
commit 55e729422b
12 changed files with 283 additions and 9 deletions

View File

@@ -1,4 +1,15 @@
@if (detail_item) {
<h1>{{ detail_item.name }}</h1>
<h2>{{ detail_item.rus_name }}</h2>
}
<div class="flex flex-col items-center">
@if (detail_item) {
<h1>{{ detail_item.name }}</h1>
<h2>{{ detail_item.rus_name }}</h2>
<img [src]="detail_item.cover.default" [alt]="detail_item.slug" />
@for (chapter of chapters.data; track $index) {
<h3>
<strong>{{ chapter.number }}.</strong> {{ chapter.name || "Нет названия" }}
</h3>
}
<button class="p-3 text-white bg-slate-600 w-[400px] mt-5 rounded-lg" (click)="goToReader()">
Читать
</button>
}
</div>

View File

@@ -1,6 +1,7 @@
import { CommonModule } from "@angular/common";
import { AfterViewInit, Component } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { IRulibChaptersResult } from "../../services/parsers/rulib/rulib.chapters.dto";
import { Data } from "../../services/parsers/rulib/rulib.detail.dto";
import { SearchService } from "../../services/search.service";
@@ -13,20 +14,41 @@ import { SearchService } from "../../services/search.service";
})
export class DetailComponent implements AfterViewInit {
detail_item: Data | null = null;
chapters: IRulibChaptersResult = { data: [] };
constructor(
private route: ActivatedRoute,
private searchService: SearchService,
private router: Router,
) {}
private getDetails(url: string) {
this.searchService.getDetails(url).subscribe((data) => {
this.detail_item = data.data;
});
this.searchService.getChapters(url).subscribe((data) => {
this.chapters = data;
});
}
ngAfterViewInit(): void {
this.route.queryParams.subscribe((params) => {
const url = params["url"];
if (url) {
this.searchService.getDetails(url).subscribe((data) => (this.detail_item = data.data));
this.getDetails(url);
} else {
this.router.navigate(["/"]);
}
});
}
goToReader() {
//TODO: Not only first chapter
this.router.navigate(["/", "reader"], {
queryParams: {
url: this.detail_item?.slug_url,
chapter: this.chapters.data[0].number,
volume: this.chapters.data[0].volume,
},
});
}
}