From 7b2c6d9fc8fdfa1afa9f8a6bd2b257a1f9778413 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Fri, 19 Jul 2024 15:06:35 +0300 Subject: [PATCH] feat: almost abstractions --- .../app/components/detail/detail.component.ts | 1 + .../src/app/components/home/home.component.ts | 1 + .../app/components/reader/reader.component.ts | 2 +- .../src/app/services/search.service.ts | 22 +++++++++++++------ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/NwaifuAnime/src/app/components/detail/detail.component.ts b/apps/NwaifuAnime/src/app/components/detail/detail.component.ts index 4dd1d59..c2254c8 100644 --- a/apps/NwaifuAnime/src/app/components/detail/detail.component.ts +++ b/apps/NwaifuAnime/src/app/components/detail/detail.component.ts @@ -56,6 +56,7 @@ export class DetailComponent implements AfterViewInit, OnDestroy { this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => { const url = params["url"]; if (url) { + this.searchService.setMangalibParser(); this.getDetails(url); } else { this.router.navigate(["/"]); diff --git a/apps/NwaifuAnime/src/app/components/home/home.component.ts b/apps/NwaifuAnime/src/app/components/home/home.component.ts index 6f8025a..6058714 100644 --- a/apps/NwaifuAnime/src/app/components/home/home.component.ts +++ b/apps/NwaifuAnime/src/app/components/home/home.component.ts @@ -33,6 +33,7 @@ export class HomeComponent implements OnDestroy, OnInit { this.route.queryParams.subscribe((params) => { const search = params["search"]; if (search) { + this.searchService.setMangalibParser(); this.loading = true; this.searchService .search(search) diff --git a/apps/NwaifuAnime/src/app/components/reader/reader.component.ts b/apps/NwaifuAnime/src/app/components/reader/reader.component.ts index 3a49f20..4b7ba5c 100644 --- a/apps/NwaifuAnime/src/app/components/reader/reader.component.ts +++ b/apps/NwaifuAnime/src/app/components/reader/reader.component.ts @@ -24,7 +24,6 @@ import { CachedPage, CachedPages } from "./reader.dto"; imports: [CommonModule, ScaleImageComponent, RouterLink], }) export class ReaderComponent implements OnInit, OnDestroy { - //FIXME: Scrolling to top when manhwa pages: Page[] = []; currentPageIndex = 0; cachedPages: CachedPages = new Map(); @@ -61,6 +60,7 @@ export class ReaderComponent implements OnInit, OnDestroy { const volume = params["volume"]; const fromTowards = params["from_towards"]; if (url && chapter && volume) { + this.searchService.setMangalibParser(); if (fromTowards) this.fromTowards = Boolean(+fromTowards); else this.fromTowards = false; this.chapterNum = +chapter; diff --git a/apps/NwaifuAnime/src/app/services/search.service.ts b/apps/NwaifuAnime/src/app/services/search.service.ts index d52aa08..9a0eb07 100644 --- a/apps/NwaifuAnime/src/app/services/search.service.ts +++ b/apps/NwaifuAnime/src/app/services/search.service.ts @@ -1,6 +1,7 @@ import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; import { BehaviorSubject, Observable, map } from "rxjs"; +import { Parser } from "./parsers/parser"; import { MangalibParserService } from "./parsers/rulib/mangalib.parser.service"; import { IRulibChapterResult } from "./parsers/rulib/rulib.chapter.dto"; import { IRulibChaptersResult } from "./parsers/rulib/rulib.chapters.dto"; @@ -11,15 +12,20 @@ import { Datum, IRulibSearchResult } from "./parsers/rulib/rulib.search.dto"; export class SearchService { private itemsTerm = new BehaviorSubject([]); currentItemsTerm = this.itemsTerm.asObservable(); + private parser!: Parser; constructor( - private parser: MangalibParserService, private http: HttpClient, + private mangalibParser: MangalibParserService, ) {} + setMangalibParser() { + this.parser = this.mangalibParser; + } + search(query: string): Observable { return this.parser.searchManga(query).pipe( map((data) => { - return data; + return data as IRulibSearchResult; }), ); } @@ -27,7 +33,7 @@ export class SearchService { getDetails(slug_url: string): Observable { return this.parser.getDetails(slug_url).pipe( map((data) => { - return data; + return data as IRulibDetailResult; }), ); } @@ -35,7 +41,7 @@ export class SearchService { getChapters(url: string): Observable { return this.parser.getChapters(url).pipe( map((data) => { - return data; + return data as IRulibChaptersResult; }), ); } @@ -43,13 +49,14 @@ export class SearchService { getChapter(url: string, chapter: string, volume: string): Observable { return this.parser.getChapter(url, chapter, volume).pipe( map((data) => { - return data; + return data as IRulibChapterResult; }), ); } getImageServer() { - return this.parser.imageServer; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (this.parser as any).imageServer; } getImageData(imageUrl: string): Observable { @@ -61,6 +68,7 @@ export class SearchService { } isManhwa(url: string): Observable { - return this.parser.isManhwa(url); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (this.parser as any).isManhwa(url); } }