From 8c9efd4371762d8ebb488952702d6bcb69cf6a42 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Sat, 20 Jul 2024 22:36:31 +0300 Subject: [PATCH] feat: click on manga page to change page --- .../components/header/header.component.less | 4 +++ .../components/reader/reader.component.html | 16 ++++++--- .../app/components/reader/reader.component.ts | 2 +- .../scale-image/scale-image.component.html | 2 +- .../scale-image/scale-image.component.ts | 36 ++++++++++++++++++- .../rulib/lib.social.parser.service.ts | 2 -- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/apps/NwaifuAnime/src/app/components/header/header.component.less b/apps/NwaifuAnime/src/app/components/header/header.component.less index ba4612c..d618ea9 100644 --- a/apps/NwaifuAnime/src/app/components/header/header.component.less +++ b/apps/NwaifuAnime/src/app/components/header/header.component.less @@ -1,3 +1,7 @@ .header { transition: height 0.3s; } +:host { + z-index: 20; + position: fixed; +} diff --git a/apps/NwaifuAnime/src/app/components/reader/reader.component.html b/apps/NwaifuAnime/src/app/components/reader/reader.component.html index 9df3033..6d5d72a 100644 --- a/apps/NwaifuAnime/src/app/components/reader/reader.component.html +++ b/apps/NwaifuAnime/src/app/components/reader/reader.component.html @@ -14,7 +14,11 @@ @if (pages.length > 0 && currentPage) {
@if (!isManhwa) { - + } @else { @for (page of manhwaPages; track page.id) { -
+
@@ -35,8 +39,10 @@ →
- + @if (isManhwa) { + + } }
diff --git a/apps/NwaifuAnime/src/app/components/reader/reader.component.ts b/apps/NwaifuAnime/src/app/components/reader/reader.component.ts index 4b7ba5c..fd9e465 100644 --- a/apps/NwaifuAnime/src/app/components/reader/reader.component.ts +++ b/apps/NwaifuAnime/src/app/components/reader/reader.component.ts @@ -240,6 +240,6 @@ export class ReaderComponent implements OnInit, OnDestroy { } get imageContainerClass() { - return `${this.isManhwa ? "h-auto" : "h-[70vh]"} w-[95vw] md:w-[450px] flex flex-col`; + return `${this.isManhwa ? "h-auto" : "h-[70vh]"} w-screen md:w-[450px] flex flex-col`; } } diff --git a/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.html b/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.html index 0c1a7c2..8734a5a 100644 --- a/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.html +++ b/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.html @@ -1,6 +1,6 @@
@if (imageSrc) { - Manga page + Manga page } @else {

Loading...

} diff --git a/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.ts b/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.ts index 5bbde19..5b52543 100644 --- a/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.ts +++ b/apps/NwaifuAnime/src/app/components/scale-image/scale-image.component.ts @@ -6,9 +6,11 @@ import { Input, OnDestroy, Output, + QueryList, ViewChild, + ViewChildren, } from "@angular/core"; -import { Subscription, debounceTime, fromEvent } from "rxjs"; +import { Subject, Subscription, debounceTime, fromEvent, map, takeUntil } from "rxjs"; @Component({ selector: "app-scale-image", @@ -20,10 +22,16 @@ export class ScaleImageComponent implements AfterViewInit, OnDestroy { @Input({ required: true }) imageSrc: string = ""; @ViewChild("container", { static: true }) containerRef: ElementRef | null = null; @ViewChild("image", { static: true }) imageRef: ElementRef | null = null; + @ViewChildren("image") imageList: QueryList> = new QueryList< + ElementRef + >(); @Output() view = new EventEmitter(); + @Output() clickLeft = new EventEmitter(); + @Output() clickRight = new EventEmitter(); @Input() host: ElementRef | null = null; @Input() hostScrollable: boolean = false; + private destroy$ = new Subject(); private resizeSubscription: Subscription = new Subscription(); private observer!: IntersectionObserver; @@ -39,11 +47,37 @@ export class ScaleImageComponent implements AfterViewInit, OnDestroy { ); if (this.containerRef) this.observer.observe(this.containerRef.nativeElement); } + if (!this.host) { + this.imageList.changes + .pipe>>(takeUntil(this.destroy$)) + .subscribe((imageList) => { + fromEvent(imageList.first.nativeElement, "click") + .pipe( + takeUntil(this.destroy$), + map((e) => e as MouseEvent), + ) + .subscribe((e) => { + const target = e.target as HTMLImageElement; + const imageWidth = target.clientWidth; + const clickX = e.offsetX; + if (clickX < imageWidth / 2) this.clickLeft.emit(); + else this.clickRight.emit(); + }); + }); + } + + // fromEvent(this.imageRef.first.nativeElement, "click") + // .pipe(takeUntil(this.destroy$)) + // .subscribe((e) => { + // console.log(e); + // }); } ngOnDestroy(): void { if (this.resizeSubscription) this.resizeSubscription.unsubscribe(); if (this.observer) this.observer.disconnect(); + this.destroy$.next(); + this.destroy$.complete(); } onImageLoad() { diff --git a/apps/NwaifuAnime/src/app/services/parsers/rulib/lib.social.parser.service.ts b/apps/NwaifuAnime/src/app/services/parsers/rulib/lib.social.parser.service.ts index 2e89fcc..42857ba 100644 --- a/apps/NwaifuAnime/src/app/services/parsers/rulib/lib.social.parser.service.ts +++ b/apps/NwaifuAnime/src/app/services/parsers/rulib/lib.social.parser.service.ts @@ -101,7 +101,6 @@ export class LibSocialParserService extends Parser { } getPopular(): Observable { - //TODO: мб сделать ассинхрон return this.http .get<{ data: { popular: [] } }>(`${this.url}/api/`, { headers: { @@ -112,7 +111,6 @@ export class LibSocialParserService extends Parser { .pipe( map((data) => { const res = data.data.popular as IRuLIBPopular[]; - console.log(res); return res; }), catchError((error) => throwError(() => `Now found ${error}`)),