Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8de238028e | |||
| 3522df4066 | |||
| d5803c4a94 |
@@ -31,7 +31,7 @@
|
|||||||
Вход через скрипт TamperMonkey. Если нет кнопки, значит вы не установили скрипт
|
Вход через скрипт TamperMonkey. Если нет кнопки, значит вы не установили скрипт
|
||||||
<a
|
<a
|
||||||
href="https://test-front.mangalib.me"
|
href="https://test-front.mangalib.me"
|
||||||
class="hover:bg-slate-600 bg-slate-400 p-3 rounded-md text-white tamperMonkey"
|
class="hover:bg-slate-600 bg-slate-400 px-3 md:py-3 py-1 rounded-md text-white tamperMonkey"
|
||||||
>
|
>
|
||||||
Вход
|
Вход
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ export class HeaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
toggleProfileMenu(event: MouseEvent) {
|
toggleProfileMenu(event: MouseEvent) {
|
||||||
if (this.profileBtn && this.profileBtn.nativeElement.contains(event.target as Node)) {
|
if (this.profileBtn && this.profileBtn.nativeElement.contains(event.target as Node)) {
|
||||||
this.menuOpened = !this.menuOpened;
|
this.menuOpened = !this.menuOpened;
|
||||||
console.log(this.menuOpened);
|
|
||||||
} else {
|
} else {
|
||||||
this.menuOpened = false;
|
this.menuOpened = false;
|
||||||
}
|
}
|
||||||
@@ -66,14 +65,6 @@ export class HeaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get menuBtnClass(): string {
|
|
||||||
return `lni ${this.menuOpened ? "lni-close" : "lni-menu"} text-white`;
|
|
||||||
}
|
|
||||||
|
|
||||||
get searchBarClass(): string {
|
|
||||||
return `search-bar bg-slate-300 md:w-full w-full md:m-0 ms-2 me-2 md:h-6 h-10 md:flex justify-start flex-row items-center rounded-md ${this.menuOpened ? "flex" : "hidden"}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
|
|||||||
@@ -16,9 +16,15 @@
|
|||||||
<img
|
<img
|
||||||
[src]="popularTitle.cover.thumbnail"
|
[src]="popularTitle.cover.thumbnail"
|
||||||
[alt]="popularTitle.slug"
|
[alt]="popularTitle.slug"
|
||||||
class="w-[200px] h-auto aspect-auto"
|
class="w-[200px] max-h-[250px] h-auto aspect-auto"
|
||||||
/>
|
/>
|
||||||
<p>{{ popularTitle.rus_name }}</p>
|
<p class="text-center">
|
||||||
|
{{
|
||||||
|
popularTitle.rus_name.length > 50
|
||||||
|
? popularTitle.rus_name.slice(0, 50) + "..."
|
||||||
|
: popularTitle.rus_name
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
@@ -28,31 +34,68 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
} @else {
|
} @else {
|
||||||
<div class="flex flex-col items-center w-full px-3 mt-3">
|
<div class="flex justify-center items-center mt-3">
|
||||||
@if (loading) {
|
@if (loading) {
|
||||||
<h1>Loading...</h1>
|
<h1>Loading...</h1>
|
||||||
}
|
} @else if (notFound && !loading) {
|
||||||
@if (notFound && !loading) {
|
|
||||||
<h1>Not found</h1>
|
<h1>Not found</h1>
|
||||||
|
} @else {
|
||||||
|
<h1>Найдено по запросу "{{ search }}" результатов: {{ items.length }}</h1>
|
||||||
}
|
}
|
||||||
@for (item of items; track $index) {
|
</div>
|
||||||
|
<div class="flex flex-col items-center justify-start gap-3">
|
||||||
|
<div
|
||||||
|
class="flex md:flex-row flex-col flex-nowrap md:flex-wrap gap-2 justify-start items-center w-full px-3 mt-3 md:mx-12"
|
||||||
|
>
|
||||||
|
@for (item of currentPageItems; track $index) {
|
||||||
<a
|
<a
|
||||||
routerLink="/detail"
|
routerLink="/detail"
|
||||||
[queryParams]="{ url: item.slug_url }"
|
[queryParams]="{ url: item.slug_url }"
|
||||||
title="{{ item.name }}"
|
title="{{ item.name }}"
|
||||||
class="mb-6 max-w-[700px] w-full"
|
class="my-1 max-w-[400px] w-full"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="card flex flex-col items-center border-black border-2 rounded-md p-4 w-full h-[350px]"
|
class="card flex flex-col items-center border-black border-2 rounded-md p-4 w-full h-[350px]"
|
||||||
>
|
>
|
||||||
<h1>{{ item.rus_name }}</h1>
|
<p class="text-center">
|
||||||
|
{{
|
||||||
|
item.rus_name.length > 50 ? item.rus_name.substring(0, 50) + "..." : item.rus_name
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
<img
|
<img
|
||||||
[src]="item.cover.thumbnail"
|
[src]="item.cover.thumbnail"
|
||||||
[alt]="item.slug"
|
[alt]="item.slug"
|
||||||
class="w-[200px] h-auto max-h-[300px] aspect-auto"
|
class="w-[200px] h-auto max-h-[250px] aspect-auto"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
@if (items.length) {
|
||||||
|
<div class="flex flex-row items-center justify-between w-full px-3">
|
||||||
|
<button
|
||||||
|
[ngClass]="{
|
||||||
|
'bg-slate-600 text-white p-3 rounded-md hover:scale-105': 1,
|
||||||
|
'opacity-15': currentPage === 0,
|
||||||
|
}"
|
||||||
|
[disabled]="currentPage === 0"
|
||||||
|
(click)="previousSearchPage()"
|
||||||
|
>
|
||||||
|
Назад
|
||||||
|
</button>
|
||||||
|
<p>Страница {{ currentPage + 1 }} из {{ maxPages + 1 }}</p>
|
||||||
|
<button
|
||||||
|
[ngClass]="{
|
||||||
|
'bg-slate-600 text-white p-3 rounded-md hover:scale-105': 1,
|
||||||
|
'opacity-15': currentPage === maxPages,
|
||||||
|
}"
|
||||||
|
[disabled]="currentPage === maxPages"
|
||||||
|
*ngIf="currentPage < items.length / 8"
|
||||||
|
(click)="nextSearchPage()"
|
||||||
|
>
|
||||||
|
Вперед
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
||||||
import { ActivatedRoute, RouterLink } from "@angular/router";
|
import { ActivatedRoute, Router, RouterLink } from "@angular/router";
|
||||||
import { map, Subject, Subscription, takeUntil } from "rxjs";
|
import { Subject, Subscription, map, takeUntil } from "rxjs";
|
||||||
import { RulibAuthService } from "../../services/parsers/rulib/rulib.auth.service";
|
import { RulibAuthService } from "../../services/parsers/rulib/rulib.auth.service";
|
||||||
import { IRuLIBPopular } from "../../services/parsers/rulib/rulib.popular.dto";
|
import { IRuLIBPopular } from "../../services/parsers/rulib/rulib.popular.dto";
|
||||||
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
||||||
@@ -20,6 +20,7 @@ export class HomeComponent implements OnDestroy, OnInit {
|
|||||||
notFound = false;
|
notFound = false;
|
||||||
search: string = "";
|
search: string = "";
|
||||||
popularItemsMap: Map<string, IRuLIBPopular[]> = new Map<string, IRuLIBPopular[]>();
|
popularItemsMap: Map<string, IRuLIBPopular[]> = new Map<string, IRuLIBPopular[]>();
|
||||||
|
currentPage = 0;
|
||||||
|
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
private popularSubscription = new Subscription();
|
private popularSubscription = new Subscription();
|
||||||
@@ -28,6 +29,7 @@ export class HomeComponent implements OnDestroy, OnInit {
|
|||||||
private searchService: SearchService,
|
private searchService: SearchService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private ruLibAuthService: RulibAuthService,
|
private ruLibAuthService: RulibAuthService,
|
||||||
|
private router: Router,
|
||||||
) {
|
) {
|
||||||
this.searchService.setMangalibParser();
|
this.searchService.setMangalibParser();
|
||||||
}
|
}
|
||||||
@@ -76,9 +78,44 @@ export class HomeComponent implements OnDestroy, OnInit {
|
|||||||
return Array.from(this.popularItemsMap.entries()).sort((a, b) => (a[0] > b[0] ? 1 : -1));
|
return Array.from(this.popularItemsMap.entries()).sort((a, b) => (a[0] > b[0] ? 1 : -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get currentPageItems() {
|
||||||
|
return this.items.slice(
|
||||||
|
8 * this.currentPage,
|
||||||
|
Math.min(this.items.length, 8 * (this.currentPage + 1)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get maxPages() {
|
||||||
|
return Math.ceil(this.items.length / 8) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextSearchPage() {
|
||||||
|
this.currentPage = Math.min(this.currentPage + 1, Math.ceil(this.items.length / 8) - 1);
|
||||||
|
this.router.navigate([], {
|
||||||
|
queryParams: { page: this.currentPage },
|
||||||
|
relativeTo: this.route,
|
||||||
|
queryParamsHandling: "merge",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
previousSearchPage() {
|
||||||
|
this.currentPage = Math.max(this.currentPage - 1, 0);
|
||||||
|
this.router.navigate([], {
|
||||||
|
queryParams: { page: this.currentPage },
|
||||||
|
relativeTo: this.route,
|
||||||
|
queryParamsHandling: "merge",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||||
|
if (this.search && params["search"] && this.search === params["search"]) return;
|
||||||
this.search = params["search"] ?? "";
|
this.search = params["search"] ?? "";
|
||||||
|
try {
|
||||||
|
this.currentPage = Math.max(0, +params["page"] || 0);
|
||||||
|
} catch {
|
||||||
|
this.currentPage = 0;
|
||||||
|
}
|
||||||
this.items = [];
|
this.items = [];
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
if (this.search) {
|
if (this.search) {
|
||||||
@@ -89,6 +126,9 @@ export class HomeComponent implements OnDestroy, OnInit {
|
|||||||
.subscribe((data) => {
|
.subscribe((data) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.items = data.data;
|
this.items = data.data;
|
||||||
|
const maxPage = Math.ceil(this.items.length / 8) - 1;
|
||||||
|
console.log(maxPage);
|
||||||
|
this.currentPage = Math.min(this.currentPage, maxPage);
|
||||||
this.notFound = this.items.length === 0;
|
this.notFound = this.items.length === 0;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user