2 Commits

Author SHA1 Message Date
2becf42487 feat: current page indicator 2024-07-19 15:57:36 +03:00
7b2c6d9fc8 feat: almost abstractions 2024-07-19 15:06:35 +03:00
5 changed files with 23 additions and 12 deletions

View File

@@ -56,6 +56,7 @@ export class DetailComponent implements AfterViewInit, OnDestroy {
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => { this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
const url = params["url"]; const url = params["url"];
if (url) { if (url) {
this.searchService.setMangalibParser();
this.getDetails(url); this.getDetails(url);
} else { } else {
this.router.navigate(["/"]); this.router.navigate(["/"]);

View File

@@ -33,6 +33,7 @@ export class HomeComponent implements OnDestroy, OnInit {
this.route.queryParams.subscribe((params) => { this.route.queryParams.subscribe((params) => {
const search = params["search"]; const search = params["search"];
if (search) { if (search) {
this.searchService.setMangalibParser();
this.loading = true; this.loading = true;
this.searchService this.searchService
.search(search) .search(search)

View File

@@ -35,5 +35,8 @@
</button> </button>
</div> </div>
<div class="hidden md:block md:fixed right-10 top-[50%]">
{{ currentPageIndex + 1 }} / {{ pages.length }}
</div>
} }
</div> </div>

View File

@@ -24,7 +24,6 @@ import { CachedPage, CachedPages } from "./reader.dto";
imports: [CommonModule, ScaleImageComponent, RouterLink], imports: [CommonModule, ScaleImageComponent, RouterLink],
}) })
export class ReaderComponent implements OnInit, OnDestroy { export class ReaderComponent implements OnInit, OnDestroy {
//FIXME: Scrolling to top when manhwa
pages: Page[] = []; pages: Page[] = [];
currentPageIndex = 0; currentPageIndex = 0;
cachedPages: CachedPages = new Map<number, CachedPage>(); cachedPages: CachedPages = new Map<number, CachedPage>();
@@ -61,6 +60,7 @@ export class ReaderComponent implements OnInit, OnDestroy {
const volume = params["volume"]; const volume = params["volume"];
const fromTowards = params["from_towards"]; const fromTowards = params["from_towards"];
if (url && chapter && volume) { if (url && chapter && volume) {
this.searchService.setMangalibParser();
if (fromTowards) this.fromTowards = Boolean(+fromTowards); if (fromTowards) this.fromTowards = Boolean(+fromTowards);
else this.fromTowards = false; else this.fromTowards = false;
this.chapterNum = +chapter; this.chapterNum = +chapter;

View File

@@ -1,25 +1,29 @@
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { BehaviorSubject, Observable, map } from "rxjs"; import { Observable, map } from "rxjs";
import { Parser } from "./parsers/parser";
import { MangalibParserService } from "./parsers/rulib/mangalib.parser.service"; import { MangalibParserService } from "./parsers/rulib/mangalib.parser.service";
import { IRulibChapterResult } from "./parsers/rulib/rulib.chapter.dto"; import { IRulibChapterResult } from "./parsers/rulib/rulib.chapter.dto";
import { IRulibChaptersResult } from "./parsers/rulib/rulib.chapters.dto"; import { IRulibChaptersResult } from "./parsers/rulib/rulib.chapters.dto";
import { IRulibDetailResult } from "./parsers/rulib/rulib.detail.dto"; import { IRulibDetailResult } from "./parsers/rulib/rulib.detail.dto";
import { Datum, IRulibSearchResult } from "./parsers/rulib/rulib.search.dto"; import { IRulibSearchResult } from "./parsers/rulib/rulib.search.dto";
@Injectable({ providedIn: "root" }) @Injectable({ providedIn: "root" })
export class SearchService { export class SearchService {
private itemsTerm = new BehaviorSubject<Datum[]>([]); private parser!: Parser;
currentItemsTerm = this.itemsTerm.asObservable();
constructor( constructor(
private parser: MangalibParserService,
private http: HttpClient, private http: HttpClient,
private mangalibParser: MangalibParserService,
) {} ) {}
setMangalibParser() {
this.parser = this.mangalibParser;
}
search(query: string): Observable<IRulibSearchResult> { search(query: string): Observable<IRulibSearchResult> {
return this.parser.searchManga(query).pipe( return this.parser.searchManga(query).pipe(
map((data) => { map((data) => {
return data; return data as IRulibSearchResult;
}), }),
); );
} }
@@ -27,7 +31,7 @@ export class SearchService {
getDetails(slug_url: string): Observable<IRulibDetailResult> { getDetails(slug_url: string): Observable<IRulibDetailResult> {
return this.parser.getDetails(slug_url).pipe( return this.parser.getDetails(slug_url).pipe(
map((data) => { map((data) => {
return data; return data as IRulibDetailResult;
}), }),
); );
} }
@@ -35,7 +39,7 @@ export class SearchService {
getChapters(url: string): Observable<IRulibChaptersResult> { getChapters(url: string): Observable<IRulibChaptersResult> {
return this.parser.getChapters(url).pipe( return this.parser.getChapters(url).pipe(
map((data) => { map((data) => {
return data; return data as IRulibChaptersResult;
}), }),
); );
} }
@@ -43,13 +47,14 @@ export class SearchService {
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> { getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
return this.parser.getChapter(url, chapter, volume).pipe( return this.parser.getChapter(url, chapter, volume).pipe(
map((data) => { map((data) => {
return data; return data as IRulibChapterResult;
}), }),
); );
} }
getImageServer() { getImageServer() {
return this.parser.imageServer; // eslint-disable-next-line @typescript-eslint/no-explicit-any
return (this.parser as any).imageServer;
} }
getImageData(imageUrl: string): Observable<Uint8Array> { getImageData(imageUrl: string): Observable<Uint8Array> {
@@ -61,6 +66,7 @@ export class SearchService {
} }
isManhwa(url: string): Observable<boolean> { isManhwa(url: string): Observable<boolean> {
return this.parser.isManhwa(url); // eslint-disable-next-line @typescript-eslint/no-explicit-any
return (this.parser as any).isManhwa(url);
} }
} }