feat: search field
This commit is contained in:
@@ -7,8 +7,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
<div class="h-12"></div>
|
<div class="md:h-12 h-16"></div>
|
||||||
<div class="content">
|
<div
|
||||||
|
class="content overflow-y-auto md:h-[calc(100vh-3rem)] h-[calc(100vh-4rem)] flex flex-col justify-between flex-shrink-0"
|
||||||
|
>
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
<app-footer></app-footer>
|
<app-footer></app-footer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="footer w-full border-t border-black bg-gray-300 pt-3">
|
<div class="footer w-full border-t border-black bg-gray-300 pt-3 h-[15rem] overflow-hidden mt-3">
|
||||||
<p class="text-3xl ps-[5rem]">DMCA Disclaimer</p>
|
<p class="text-3xl ps-[5rem]">DMCA Disclaimer</p>
|
||||||
<div class="footer-content h-full px-[5rem] py-6 flex flex-col gap-3">
|
<div class="footer-content h-full px-[5rem] flex flex-col gap-3">
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<p>На русском:</p>
|
<p>На русском:</p>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
<div
|
<div
|
||||||
class="header fixed flex flex-row items-center px-2 justify-between top-0 left-0 h-12 bg-gray-700 w-full"
|
class="header fixed flex flex-col items-center px-2 justify-start gap-1 md:justify-between top-0 left-0 md:h-12 h-16 bg-gray-700 w-full md:flex-row"
|
||||||
>
|
>
|
||||||
<a routerLink="/" title="Main page"><p class="text-xl text-white">NwaifuAnime</p></a>
|
<a routerLink="/" title="Main page"><p class="text-xl text-white">NwaifuAnime</p></a>
|
||||||
<app-search-field></app-search-field>
|
<app-search-field></app-search-field>
|
||||||
|
<button title="Profile" #profileBtn class="hidden md:block">
|
||||||
|
<div class="profile-btn bg-white rounded-full w-8 h-8 aspect-square ms-3">
|
||||||
|
<img src="pic/Blank-profile.png" alt="Profile pic" class="w-full h-full" />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
[class]="
|
||||||
|
'profile-menu hidden md:flex flex-col overflow-hidden z-20 rounded-md w-32 bg-white border border-black p-3 h-full fixed ' +
|
||||||
|
(menuOpened ? 'max-h-32 opacity-100' : 'max-h-0 opacity-0')
|
||||||
|
"
|
||||||
|
#profileMenu
|
||||||
|
>
|
||||||
|
<a routerLink="/auth" title="Auth page"><p class="hover:text-blue-400">Auth</p></a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,3 +5,6 @@
|
|||||||
z-index: 20;
|
z-index: 20;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
}
|
}
|
||||||
|
.profile-menu {
|
||||||
|
transition: max-height 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, OnDestroy } from "@angular/core";
|
import {
|
||||||
import { ActivatedRoute, NavigationEnd, Router, RouterLink } from "@angular/router";
|
AfterViewInit,
|
||||||
import { Subject, filter, takeUntil } from "rxjs";
|
Component,
|
||||||
|
ElementRef,
|
||||||
|
HostListener,
|
||||||
|
OnDestroy,
|
||||||
|
ViewChild,
|
||||||
|
} from "@angular/core";
|
||||||
|
import { RouterLink } from "@angular/router";
|
||||||
|
import { Subject } from "rxjs";
|
||||||
import { SearchFieldComponent } from "../search-field/search-field.component";
|
import { SearchFieldComponent } from "../search-field/search-field.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -11,28 +18,37 @@ import { SearchFieldComponent } from "../search-field/search-field.component";
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, RouterLink, SearchFieldComponent],
|
imports: [CommonModule, RouterLink, SearchFieldComponent],
|
||||||
})
|
})
|
||||||
export class HeaderComponent implements OnDestroy {
|
export class HeaderComponent implements AfterViewInit, OnDestroy {
|
||||||
menuOpened = false;
|
menuOpened = false;
|
||||||
|
@ViewChild("profileBtn") profileBtn: ElementRef<HTMLButtonElement> | null = null;
|
||||||
|
@ViewChild("profileMenu") profileMenu: ElementRef<HTMLDivElement> | null = null;
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
constructor(
|
|
||||||
private router: Router,
|
@HostListener("window:click", ["$event"])
|
||||||
private route: ActivatedRoute,
|
toggleProfileMenu(event: MouseEvent) {
|
||||||
) {
|
if (this.profileBtn && this.profileBtn.nativeElement.contains(event.target as Node)) {
|
||||||
this.router.events
|
this.menuOpened = !this.menuOpened;
|
||||||
.pipe(
|
console.log(this.menuOpened);
|
||||||
filter((event) => event instanceof NavigationEnd),
|
} else {
|
||||||
takeUntil(this.destroy$),
|
this.menuOpened = false;
|
||||||
)
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
.subscribe((val: any) => {
|
|
||||||
if (val.url.startsWith("/detail") || val.url.startsWith("/reader")) {
|
|
||||||
this.menuOpened = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changeMenu() {
|
ngAfterViewInit(): void {
|
||||||
this.menuOpened = !this.menuOpened;
|
this.moveProfileMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostListener("window:resize")
|
||||||
|
moveProfileMenu() {
|
||||||
|
if (this.profileBtn && this.profileMenu) {
|
||||||
|
const btnRect = this.profileBtn.nativeElement.getBoundingClientRect();
|
||||||
|
const menuRect = this.profileMenu.nativeElement.getBoundingClientRect();
|
||||||
|
const menuWidth = menuRect.width;
|
||||||
|
const menuX = btnRect.left + btnRect.width / 2 - menuWidth * 0.8;
|
||||||
|
const menuY = btnRect.top + btnRect.height;
|
||||||
|
this.profileMenu.nativeElement.style.left = `${menuX}px`;
|
||||||
|
this.profileMenu.nativeElement.style.top = `calc(${menuY}px + 0.25rem)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get menuBtnClass(): string {
|
get menuBtnClass(): string {
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
<div class="flex flex-row gap-3 justify-between items-center">
|
<div class="flex flex-row gap-3 justify-between items-center md:justify-end">
|
||||||
<div class="input-block max-h-0"></div>
|
<div
|
||||||
<div class="input-btn rounded-full w-8 h-8 bg-slate-400 flex justify-center items-center">
|
[class]="
|
||||||
<i class="lni lni-search-alt"></i>
|
'input-block rounded-md bg-white transition-[width] delay-150 duration-300 ease-in-out h-full overflow-hidden flex justify-center items-center w-full ' +
|
||||||
|
(openSearchField ? 'md:w-[300px]' : 'md:w-0')
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
#searchInput
|
||||||
|
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
|
||||||
|
placeholder="Начать поиск"
|
||||||
|
(keydown.enter)="search()"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<button (click)="toggleSearchField()" class="hidden md:block">
|
||||||
|
<div class="input-btn rounded-full w-8 h-8 bg-slate-400 flex justify-center items-center">
|
||||||
|
<i class="lni lni-search-alt text-white"></i>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
:host {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
|
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
|
||||||
import { Subject, takeUntil } from "rxjs";
|
import { Subject, filter, takeUntil } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-search-field",
|
selector: "app-search-field",
|
||||||
@@ -12,6 +12,7 @@ import { Subject, takeUntil } from "rxjs";
|
|||||||
})
|
})
|
||||||
export class SearchFieldComponent implements AfterViewInit, OnDestroy {
|
export class SearchFieldComponent implements AfterViewInit, OnDestroy {
|
||||||
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
|
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
|
||||||
|
openSearchField = false;
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -24,17 +25,38 @@ export class SearchFieldComponent implements AfterViewInit, OnDestroy {
|
|||||||
const search = params["search"];
|
const search = params["search"];
|
||||||
if (search && this.searchInput) {
|
if (search && this.searchInput) {
|
||||||
this.searchInput.nativeElement.value = search;
|
this.searchInput.nativeElement.value = search;
|
||||||
|
this.openSearchField = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.router.events
|
||||||
|
.pipe(
|
||||||
|
filter((event) => event instanceof NavigationEnd),
|
||||||
|
takeUntil(this.destroy$),
|
||||||
|
)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
.subscribe((event: any) => {
|
||||||
|
if (event.url === "/" && this.searchInput) {
|
||||||
|
this.searchInput.nativeElement.value = "";
|
||||||
|
this.openSearchField = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
|
console.log(this.searchInput);
|
||||||
if (this.searchInput && this.searchInput.nativeElement.value)
|
if (this.searchInput && this.searchInput.nativeElement.value)
|
||||||
this.router.navigate(["/", "search"], {
|
this.router.navigate(["/"], {
|
||||||
queryParams: { search: this.searchInput.nativeElement.value },
|
queryParams: { search: this.searchInput.nativeElement.value },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleSearchField() {
|
||||||
|
this.openSearchField = !this.openSearchField;
|
||||||
|
if (this.openSearchField && this.searchInput) {
|
||||||
|
this.searchInput.nativeElement.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
|
|||||||
Reference in New Issue
Block a user