diff --git a/apps/NwaifuAnime/src/app/app.config.ts b/apps/NwaifuAnime/src/app/app.config.ts
index 05a04f4..1ba75e8 100644
--- a/apps/NwaifuAnime/src/app/app.config.ts
+++ b/apps/NwaifuAnime/src/app/app.config.ts
@@ -3,6 +3,9 @@ import { ApplicationConfig, isDevMode, provideZoneChangeDetection } from "@angul
import { provideRouter } from "@angular/router";
import { provideServiceWorker } from "@angular/service-worker";
import { appRoutes } from "./app.routes";
+import { Parser } from "./services/parsers/parser";
+import { MangalibParserService } from "./services/parsers/rulib/mangalib.parser.service";
+import { SlashlibParserService } from "./services/parsers/rulib/slashlib.parser.service";
export const appConfig: ApplicationConfig = {
providers: [
@@ -13,5 +16,7 @@ export const appConfig: ApplicationConfig = {
registrationStrategy: "registerWhenStable:30000",
}),
provideHttpClient(withFetch()),
+ { provide: Parser, multi: true, useClass: MangalibParserService },
+ { provide: Parser, multi: true, useClass: SlashlibParserService },
],
};
diff --git a/apps/NwaifuAnime/src/app/components/home/home.component.html b/apps/NwaifuAnime/src/app/components/home/home.component.html
index fe14cb8..cd94647 100644
--- a/apps/NwaifuAnime/src/app/components/home/home.component.html
+++ b/apps/NwaifuAnime/src/app/components/home/home.component.html
@@ -1,4 +1,12 @@
It's home component
+@if (!search) {
+ @for (popular of popularItems; track popular[0]) {
+ {{ popular[0] }}
+ @for (popularTitle of popular[1]; track popularTitle.id) {
+ {{ popularTitle.rus_name }}
+ }
+ }
+}
@if (loading) {
Loading...
diff --git a/apps/NwaifuAnime/src/app/components/home/home.component.ts b/apps/NwaifuAnime/src/app/components/home/home.component.ts
index 6058714..3a4b8b6 100644
--- a/apps/NwaifuAnime/src/app/components/home/home.component.ts
+++ b/apps/NwaifuAnime/src/app/components/home/home.component.ts
@@ -1,7 +1,8 @@
import { CommonModule } from "@angular/common";
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute, RouterLink } from "@angular/router";
-import { Subject, takeUntil } from "rxjs";
+import { map, Subject, Subscription, takeUntil } from "rxjs";
+import { IRuLIBPopular } from "../../services/parsers/rulib/rulib.popular.dto";
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
import { SearchService } from "../../services/search.service";
@@ -16,33 +17,73 @@ export class HomeComponent implements OnDestroy, OnInit {
@Input() items: Datum[] = [];
loading = false;
notFound = false;
+ search: string = "";
+ popularItemsMap: Map = new Map();
private destroy$ = new Subject();
+ private popularSubscription = new Subscription();
constructor(
private searchService: SearchService,
private route: ActivatedRoute,
- ) {}
+ ) {
+ this.searchService.setMangalibParser();
+ }
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
+ this.popularSubscription.unsubscribe();
+ }
+
+ private getPopular() {
+ if (!this.popularSubscription.closed) this.popularSubscription.unsubscribe();
+ this.popularSubscription = this.searchService
+ .getPopular()
+ .pipe(map((data) => data as IRuLIBPopular[]))
+ .subscribe({
+ next: (data) => {
+ this.popularItemsMap.set(this.searchService.getRuLibName(), data);
+ console.log(this.popularItemsMap);
+ },
+ error: (error) => {
+ console.error(error);
+ },
+ });
+ }
+
+ getPopularMangalib() {
+ this.searchService.setMangalibParser();
+ this.getPopular();
+ }
+
+ getPopularSlashlib() {
+ this.searchService.setSlashlibParser();
+ this.getPopular();
+ }
+
+ get popularItems() {
+ return this.popularItemsMap.entries();
}
ngOnInit(): void {
- this.route.queryParams.subscribe((params) => {
- const search = params["search"];
- if (search) {
- this.searchService.setMangalibParser();
+ this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
+ this.search = params["search"] ?? "";
+ this.items = [];
+ if (this.search) {
this.loading = true;
+ this.searchService.setMangalibParser();
this.searchService
- .search(search)
+ .search(this.search)
.pipe(takeUntil(this.destroy$))
.subscribe((data) => {
this.loading = false;
this.items = data.data;
this.notFound = this.items.length === 0;
});
+ } else {
+ this.getPopularMangalib();
+ this.getPopularSlashlib();
}
});
}
diff --git a/apps/NwaifuAnime/src/app/services/parsers/enums/parser.ts b/apps/NwaifuAnime/src/app/services/parsers/enums/parser.ts
new file mode 100644
index 0000000..87aa692
--- /dev/null
+++ b/apps/NwaifuAnime/src/app/services/parsers/enums/parser.ts
@@ -0,0 +1,4 @@
+export enum EParser {
+ MangaLib = 0,
+ SlashLib = 1,
+}
diff --git a/apps/NwaifuAnime/src/app/services/parsers/parser.ts b/apps/NwaifuAnime/src/app/services/parsers/parser.ts
index 0a751cf..0793eba 100644
--- a/apps/NwaifuAnime/src/app/services/parsers/parser.ts
+++ b/apps/NwaifuAnime/src/app/services/parsers/parser.ts
@@ -15,4 +15,6 @@ export abstract class Parser {
abstract getChapters(url: string): Observable