feat: start search pages
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
Вход через скрипт TamperMonkey. Если нет кнопки, значит вы не установили скрипт
|
||||
<a
|
||||
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>
|
||||
|
||||
@@ -16,9 +16,15 @@
|
||||
<img
|
||||
[src]="popularTitle.cover.thumbnail"
|
||||
[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>
|
||||
</a>
|
||||
}
|
||||
@@ -28,31 +34,46 @@
|
||||
</div>
|
||||
}
|
||||
} @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) {
|
||||
<h1>Loading...</h1>
|
||||
}
|
||||
@if (notFound && !loading) {
|
||||
} @else if (notFound && !loading) {
|
||||
<h1>Not found</h1>
|
||||
} @else {
|
||||
<h1>Найдено по запросу "{{ search }}" результатов: {{ items.length }}</h1>
|
||||
}
|
||||
</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 items; track $index) {
|
||||
<a
|
||||
routerLink="/detail"
|
||||
[queryParams]="{ url: item.slug_url }"
|
||||
title="{{ item.name }}"
|
||||
class="mb-6 max-w-[700px] w-full"
|
||||
class="my-1 max-w-[400px] w-full"
|
||||
>
|
||||
<div
|
||||
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
|
||||
[src]="item.cover.thumbnail"
|
||||
[alt]="item.slug"
|
||||
class="w-[200px] h-auto max-h-[300px] aspect-auto"
|
||||
class="w-[200px] h-auto max-h-[250px] aspect-auto"
|
||||
/>
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
<div class="flex flex-row items-center justify-between">
|
||||
<button *ngIf="currentPage > 0">Назад</button>
|
||||
<button *ngIf="currentPage < items.length / 8 - 1">Вперед</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ export class HomeComponent implements OnDestroy, OnInit {
|
||||
notFound = false;
|
||||
search: string = "";
|
||||
popularItemsMap: Map<string, IRuLIBPopular[]> = new Map<string, IRuLIBPopular[]>();
|
||||
currentPage = 0;
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private popularSubscription = new Subscription();
|
||||
@@ -79,6 +80,11 @@ export class HomeComponent implements OnDestroy, OnInit {
|
||||
ngOnInit(): void {
|
||||
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||
this.search = params["search"] ?? "";
|
||||
try {
|
||||
this.currentPage = +params["page"] ?? 0;
|
||||
} catch {
|
||||
this.currentPage = 0;
|
||||
}
|
||||
this.items = [];
|
||||
this.loading = true;
|
||||
if (this.search) {
|
||||
@@ -89,6 +95,8 @@ export class HomeComponent implements OnDestroy, OnInit {
|
||||
.subscribe((data) => {
|
||||
this.loading = false;
|
||||
this.items = data.data;
|
||||
const maxPage = Math.floor(this.items.length / 8) - 1;
|
||||
this.currentPage = Math.min(this.currentPage, maxPage);
|
||||
this.notFound = this.items.length === 0;
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user