feat: started manhwa scrolling
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component, OnDestroy } from "@angular/core";
|
||||
import { ActivatedRoute, Router, RouterLink } from "@angular/router";
|
||||
import { Observable, Subject, map, takeUntil } from "rxjs";
|
||||
import { BehaviorSubject, Observable, Subject, map, takeUntil } from "rxjs";
|
||||
import { Chapter, Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
||||
import { IRulibChapter } from "../../services/parsers/rulib/rulib.chapters.dto";
|
||||
import { SearchService } from "../../services/search.service";
|
||||
@@ -28,6 +28,7 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
||||
url = "";
|
||||
private fromTowards = false;
|
||||
private destroy$ = new Subject<void>();
|
||||
private isManhwa$ = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@@ -37,6 +38,7 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
this.isManhwa$.complete();
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
@@ -62,6 +64,29 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
||||
this.router.navigate(["/"]);
|
||||
}
|
||||
});
|
||||
this.isManhwa$.pipe(takeUntil(this.destroy$)).subscribe((isManhwa) => {
|
||||
this.isManhwa = isManhwa;
|
||||
if (isManhwa) this.initManhwaScroll();
|
||||
else this.noManhwaScroll();
|
||||
});
|
||||
}
|
||||
|
||||
private handleScrollManhwa(event: Event) {
|
||||
console.log(event);
|
||||
}
|
||||
|
||||
private initManhwaScroll() {
|
||||
const component = document.querySelector("app-reader");
|
||||
if (component && this.isManhwa) {
|
||||
component.addEventListener("scroll", this.handleScrollManhwa.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
private noManhwaScroll() {
|
||||
const component = document.querySelector("app-reader");
|
||||
if (component && !this.isManhwa) {
|
||||
component.removeEventListener("scroll", this.handleScrollManhwa.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
backToTitle() {
|
||||
@@ -203,7 +228,7 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
||||
const imageUrl = this.imageUrl;
|
||||
const image = new Image();
|
||||
image.onload = () => {
|
||||
this.isManhwa = image.naturalHeight / image.naturalWidth >= 5;
|
||||
this.isManhwa$.next(image.naturalHeight / image.naturalWidth >= 5);
|
||||
URL.revokeObjectURL(imageUrl);
|
||||
};
|
||||
image.src = imageUrl;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Injectable, OnDestroy } from "@angular/core";
|
||||
import { Subject } from "rxjs";
|
||||
import { INotification } from "./notification.dto";
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
})
|
||||
export class NotificationService {
|
||||
export class NotificationService implements OnDestroy {
|
||||
readonly notification$ = new Subject<INotification>();
|
||||
|
||||
private sendNotification(message: INotification) {
|
||||
@@ -29,4 +29,8 @@ export class NotificationService {
|
||||
name: title,
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.notification$.complete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user