4 Commits

Author SHA1 Message Date
9973637a92 feat: tab-bar 2024-07-22 01:26:19 +03:00
7904abd782 fix: reader scrolling 2024-07-22 00:42:21 +03:00
f53c36bea4 feat: search field 2024-07-22 00:40:40 +03:00
16d631423c feat: header refactor starting 2024-07-21 21:03:41 +03:00
18 changed files with 231 additions and 122 deletions

View File

@@ -7,9 +7,13 @@
}
}
<app-header></app-header>
<div class="h-10"></div>
<div class="content">
<div class="md:h-12 h-16"></div>
<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>
<app-footer></app-footer>
<div class="md:min-h-0 min-h-16"></div>
</div>
<app-tab-bar></app-tab-bar>
<app-notification></app-notification>

View File

@@ -1,4 +1,3 @@
.content {
overflow-y: auto;
height: calc(100vh - 3rem);
}

View File

@@ -4,6 +4,7 @@ import { AppService } from "./app.service";
import { FooterComponent } from "./components/footer/footer.component";
import { HeaderComponent } from "./components/header/header.component";
import { NotificationComponent } from "./components/notification/notification.component";
import { TabBarComponent } from "./components/tab-bar/tab-bar.component";
@Component({
standalone: true,
@@ -13,6 +14,7 @@ import { NotificationComponent } from "./components/notification/notification.co
NotificationComponent,
NotificationComponent,
FooterComponent,
TabBarComponent,
],
selector: "app-root",
templateUrl: "./app.component.html",

View File

@@ -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 min-h-[15rem] mt-3">
<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">
<p>На русском:</p>
<p>

View File

@@ -1,73 +1,20 @@
<div
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>
<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]="
'header fixed flex justify-between w-full px-2 bg-gray-700 md:h-10 items-center md:flex-row flex-col md:gap-0 gap-3 text-xl md:text-base ' +
(menuOpened ? 'h-screen' : '')
'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
>
<div class="flex justify-between flex-row w-full align-middle h-8 items-center">
<div class="flex flex-row gap-3 h-full items-center">
<a routerLink="/" class="h-full px-2 flex justify-center items-center justify-self-center"
><h1 class="text-white" title="Main page">NwaifuAnime</h1></a
>
<div class="border-l border-white h-full"></div>
<div class="flex-row gap-3 md:flex hidden h-full items-center">
<a
routerLink="/auth"
class="h-full px-2 flex justify-center items-center hover:bg-gray-600 transition ease-in-out delay-150 duration-300"
><h2 class="text-white" title="Auth page">Auth</h2></a
>
</div>
</div>
<!-- Search bar on small screens -->
<button
type="button"
class="md:hidden flex justify-center items-center px-2"
(click)="changeMenu()"
>
<i [class]="menuBtnClass"></i>
</button>
</div>
<div
class="flex flex-col md:flex-row md:justify-end justify-center items-center gap-3 md:w-[50vw] h-full w-full"
>
<!-- Search bar on big screens -->
<div [class]="searchBarClass">
<input
type="search"
#searchInput
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
(keydown.enter)="search()"
placeholder="Начать поиск"
/>
<button
class="align-middle w-[100px] text-center border-0 flex flex-col items-center justify-center"
type="submit"
(click)="search()"
>
<span class="text-sm text-black h-full">Поиск</span>
</button>
</div>
<div class="profile-pic hidden md:block">
<!-- TODO: profile pic of current user -->
<img
src="pic/Blank-profile.png"
alt="Profile pic"
class="aspect-square w-8 bg-white rounded-md"
/>
</div>
<div
[class]="
'flex flex-col w-full justify-start items-center md:hidden overflow-hidden ' +
(menuOpened ? 'h-auto' : 'h-0')
"
>
<a
routerLink="/auth"
class="h-full px-2 flex justify-center items-center hover:bg-gray-600 transition ease-in-out delay-150 duration-300"
><h2 class="text-white" title="Auth page">Auth</h2></a
>
</div>
</div>
<a routerLink="/auth" title="Auth page"><p class="hover:text-blue-400">Auth</p></a>
</div>

View File

@@ -5,3 +5,6 @@
z-index: 20;
position: fixed;
}
.profile-menu {
transition: max-height 0.3s ease-in-out;
}

View File

@@ -1,41 +1,54 @@
import { CommonModule } from "@angular/common";
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
import { ActivatedRoute, NavigationEnd, Router, RouterLink } from "@angular/router";
import { Subject, filter, takeUntil } from "rxjs";
import {
AfterViewInit,
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";
@Component({
selector: "app-header",
templateUrl: "./header.component.html",
styleUrls: ["./header.component.less"],
standalone: true,
imports: [CommonModule, RouterLink],
imports: [CommonModule, RouterLink, SearchFieldComponent],
})
export class HeaderComponent implements AfterViewInit, OnDestroy {
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
menuOpened = false;
@ViewChild("profileBtn") profileBtn: ElementRef<HTMLButtonElement> | null = null;
@ViewChild("profileMenu") profileMenu: ElementRef<HTMLDivElement> | null = null;
private destroy$ = new Subject<void>();
constructor(
private router: Router,
private route: ActivatedRoute,
) {
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
takeUntil(this.destroy$),
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.subscribe((val: any) => {
if (val.url.startsWith("/detail") || val.url.startsWith("/reader")) {
this.menuOpened = false;
} else if (val.url === "/") {
if (this.searchInput) {
this.searchInput.nativeElement.value = "";
}
}
});
@HostListener("window:click", ["$event"])
toggleProfileMenu(event: MouseEvent) {
if (this.profileBtn && this.profileBtn.nativeElement.contains(event.target as Node)) {
this.menuOpened = !this.menuOpened;
console.log(this.menuOpened);
} else {
this.menuOpened = false;
}
}
changeMenu() {
this.menuOpened = !this.menuOpened;
ngAfterViewInit(): void {
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 {
@@ -46,22 +59,6 @@ export class HeaderComponent implements AfterViewInit, OnDestroy {
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"}`;
}
search() {
if (this.searchInput) {
const text = this.searchInput.nativeElement.value;
this.router.navigateByUrl(`/?search=${text}`);
}
}
ngAfterViewInit(): void {
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
const search = params["search"];
if (search && this.searchInput) {
this.searchInput.nativeElement.value = search;
}
});
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();

View File

@@ -28,7 +28,7 @@
</div>
}
} @else {
<div class="flex flex-col items-center w-full px-3">
<div class="flex flex-col items-center w-full px-3 mt-3">
@if (loading) {
<h1>Loading...</h1>
}

View File

@@ -0,0 +1,3 @@
:host {
height: max-content;
}

View File

@@ -1,5 +0,0 @@
:host {
overflow-y: auto;
height: 100%;
display: block;
}

View File

@@ -0,0 +1,21 @@
<div class="flex flex-row gap-3 justify-between items-center md:justify-end">
<div
[class]="
'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>
<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>

View File

@@ -0,0 +1,3 @@
:host {
width: 100%;
}

View File

@@ -0,0 +1,64 @@
import { CommonModule } from "@angular/common";
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
import { Subject, filter, takeUntil } from "rxjs";
@Component({
selector: "app-search-field",
standalone: true,
imports: [CommonModule],
templateUrl: "./search-field.component.html",
styleUrl: "./search-field.component.less",
})
export class SearchFieldComponent implements AfterViewInit, OnDestroy {
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
openSearchField = false;
private destroy$ = new Subject<void>();
constructor(
private route: ActivatedRoute,
private router: Router,
) {}
ngAfterViewInit(): void {
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
const search = params["search"];
if (search && this.searchInput) {
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() {
console.log(this.searchInput);
if (this.searchInput && this.searchInput.nativeElement.value)
this.router.navigate(["/"], {
queryParams: { search: this.searchInput.nativeElement.value },
});
}
toggleSearchField() {
this.openSearchField = !this.openSearchField;
if (this.openSearchField && this.searchInput) {
this.searchInput.nativeElement.focus();
}
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}

View File

@@ -0,0 +1,16 @@
<div
class="flex flex-row justify-start items-center md:hidden fixed bottom-0 w-full bg-gray-700 h-16 px-3"
>
@for (link of links; track link.link) {
<a [routerLink]="link.link">
<div class="tab-bar__item flex flex-col justify-center items-center h-full center w-16">
<i
[class]="
'text-3xl ' + link.line_icon + ' ' + (link.active ? 'text-white' : 'text-gray-500')
"
></i>
<span [class]="link.active ? 'text-white' : 'text-gray-500'">Auth</span>
</div>
</a>
}
</div>

View File

@@ -0,0 +1,3 @@
:host {
display: block;
}

View File

@@ -0,0 +1,41 @@
import { CommonModule } from "@angular/common";
import { Component, OnDestroy } from "@angular/core";
import { NavigationEnd, Router, RouterLink } from "@angular/router";
import { Subject, filter, takeUntil } from "rxjs";
import { ITab } from "./tab-bar.dto";
@Component({
selector: "app-tab-bar",
standalone: true,
imports: [CommonModule, RouterLink],
templateUrl: "./tab-bar.component.html",
styleUrl: "./tab-bar.component.less",
})
export class TabBarComponent implements OnDestroy {
links: ITab[] = [
{
link: "/auth",
line_icon: "lni lni-user",
name: "Auth",
active: false,
},
];
private destroy$ = new Subject<void>();
constructor(private router: Router) {
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
takeUntil(this.destroy$),
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.subscribe((event: any) => {
this.links.forEach((link) => {
link.active = event.url.startsWith(link.link);
});
});
}
ngOnDestroy(): void {
throw new Error("Method not implemented.");
}
}

View File

@@ -0,0 +1,6 @@
export interface ITab {
link: string;
line_icon: string;
name: string;
active: boolean;
}

View File

@@ -36,5 +36,10 @@
]
}
},
"nxCloudAccessToken": "${NX_CLOUD_ACCESS_TOKEN}"
"nxCloudAccessToken": "${NX_CLOUD_ACCESS_TOKEN}",
"generators": {
"@nx/angular:component": {
"style": "less"
}
}
}