diff --git a/apps/NwaifuAnime/src/app/components/home/home.component.html b/apps/NwaifuAnime/src/app/components/home/home.component.html index cd94647..fa4a2c1 100644 --- a/apps/NwaifuAnime/src/app/components/home/home.component.html +++ b/apps/NwaifuAnime/src/app/components/home/home.component.html @@ -1,30 +1,56 @@ -

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...

+

Подождите...

+ } @else { +

Популярное:

+
+ @for (popular of popularItems; track popular[0]) { +

{{ popular[0] }}

+
+
+ @for (popularTitle of popular[1]; track popularTitle.id) { + +
+ +

{{ popularTitle.rus_name }}

+
+
+ } +
+
+ } +
} - @if (notFound && !loading) { -

Not found

- } - @for (item of items; track $index) { - -
-

{{ item.rus_name }}

- -
-
- } -
+} @else { +
+ @if (loading) { +

Loading...

+ } + @if (notFound && !loading) { +

Not found

+ } + @for (item of items; track $index) { + +
+

{{ item.rus_name }}

+ +
+
+ } +
+} diff --git a/apps/NwaifuAnime/src/app/components/home/home.component.ts b/apps/NwaifuAnime/src/app/components/home/home.component.ts index 3a4b8b6..e7ea50e 100644 --- a/apps/NwaifuAnime/src/app/components/home/home.component.ts +++ b/apps/NwaifuAnime/src/app/components/home/home.component.ts @@ -36,15 +36,17 @@ export class HomeComponent implements OnDestroy, OnInit { this.popularSubscription.unsubscribe(); } - private getPopular() { - if (!this.popularSubscription.closed) this.popularSubscription.unsubscribe(); - this.popularSubscription = this.searchService + private getPopular(parserName: string) { + this.searchService .getPopular() - .pipe(map((data) => data as IRuLIBPopular[])) + .pipe( + map((data) => data as IRuLIBPopular[]), + takeUntil(this.destroy$), + ) .subscribe({ next: (data) => { - this.popularItemsMap.set(this.searchService.getRuLibName(), data); - console.log(this.popularItemsMap); + this.popularItemsMap.set(parserName, data); + this.loading = false; }, error: (error) => { console.error(error); @@ -52,26 +54,26 @@ export class HomeComponent implements OnDestroy, OnInit { }); } - getPopularMangalib() { + private getPopularMangalib() { this.searchService.setMangalibParser(); - this.getPopular(); + this.getPopular(this.searchService.getRuLibName()); } - getPopularSlashlib() { + private getPopularSlashlib() { this.searchService.setSlashlibParser(); - this.getPopular(); + this.getPopular(this.searchService.getRuLibName()); } get popularItems() { - return this.popularItemsMap.entries(); + return Array.from(this.popularItemsMap.entries()).sort((a, b) => (a[0] > b[0] ? 1 : -1)); } ngOnInit(): void { this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => { this.search = params["search"] ?? ""; this.items = []; + this.loading = true; if (this.search) { - this.loading = true; this.searchService.setMangalibParser(); this.searchService .search(this.search)