feat: started work with directive

This commit is contained in:
2024-07-15 00:05:58 +03:00
parent 45389364ff
commit c9c959ce76
3 changed files with 27 additions and 6 deletions

View File

@@ -0,0 +1,19 @@
import { Directive, ElementRef } from "@angular/core";
@Directive({
selector: "[appLazyLoad]",
standalone: true,
})
export class LazyLoadDirective {
constructor({ nativeElement }: ElementRef) {
const observer = new IntersectionObserver(
(entries) => {
console.log(entries);
},
{
rootMargin: "1000px",
},
);
observer.observe(nativeElement);
}
}

View File

@@ -21,6 +21,7 @@
} }
} }
</div> </div>
<div appLazyLoad></div>
<div class="flex items-center justify-center space-x-4 my-10"> <div class="flex items-center justify-center space-x-4 my-10">
<button (click)="prevPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg"> <button (click)="prevPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg">

View File

@@ -15,6 +15,7 @@ import { Chapter, Page } from "../../services/parsers/rulib/rulib.chapter.dto";
import { IRulibChapter } from "../../services/parsers/rulib/rulib.chapters.dto"; import { IRulibChapter } from "../../services/parsers/rulib/rulib.chapters.dto";
import { SearchService } from "../../services/search.service"; import { SearchService } from "../../services/search.service";
import { ScaleImageComponent } from "../scale-image/scale-image.component"; import { ScaleImageComponent } from "../scale-image/scale-image.component";
import { LazyLoadDirective } from "./lazyscroll.directive";
import { CachedPage, CachedPages } from "./reader.dto"; import { CachedPage, CachedPages } from "./reader.dto";
@Component({ @Component({
@@ -22,7 +23,7 @@ import { CachedPage, CachedPages } from "./reader.dto";
templateUrl: "./reader.component.html", templateUrl: "./reader.component.html",
styleUrls: ["./reader.component.less"], styleUrls: ["./reader.component.less"],
standalone: true, standalone: true,
imports: [CommonModule, ScaleImageComponent, RouterLink], imports: [CommonModule, ScaleImageComponent, RouterLink, LazyLoadDirective],
}) })
export class ReaderComponent implements AfterViewInit, OnDestroy { export class ReaderComponent implements AfterViewInit, OnDestroy {
//FIXME: Scrolling to top when manhwa //FIXME: Scrolling to top when manhwa
@@ -79,11 +80,11 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
this.router.navigate(["/"]); this.router.navigate(["/"]);
} }
}); });
this.isManhwa$.pipe(takeUntil(this.destroy$)).subscribe((isManhwa) => { // this.isManhwa$.pipe(takeUntil(this.destroy$)).subscribe((isManhwa) => {
this.isManhwa = isManhwa; // this.isManhwa = isManhwa;
if (isManhwa) this.initManhwaScroll(); // if (isManhwa) this.initManhwaScroll();
else this.noManhwaScroll(); // else this.noManhwaScroll();
}); // });
} }
private handleScrollManhwa(event: Event) { private handleScrollManhwa(event: Event) {