diff --git a/apps/NwaifuAnime/src/app/app.component.html b/apps/NwaifuAnime/src/app/app.component.html index 108fcc6..36910c1 100644 --- a/apps/NwaifuAnime/src/app/app.component.html +++ b/apps/NwaifuAnime/src/app/app.component.html @@ -7,7 +7,7 @@ } } -
+
diff --git a/apps/NwaifuAnime/src/app/components/header/header.component.html b/apps/NwaifuAnime/src/app/components/header/header.component.html index 2c1831c..c10864d 100644 --- a/apps/NwaifuAnime/src/app/components/header/header.component.html +++ b/apps/NwaifuAnime/src/app/components/header/header.component.html @@ -1,73 +1,6 @@
-
-
-

NwaifuAnime

-
- -
- - - -
- -
- -
- - -
- -
-

Auth

-
-
+

NwaifuAnime

+
diff --git a/apps/NwaifuAnime/src/app/components/header/header.component.ts b/apps/NwaifuAnime/src/app/components/header/header.component.ts index 7414b81..eb8bc88 100644 --- a/apps/NwaifuAnime/src/app/components/header/header.component.ts +++ b/apps/NwaifuAnime/src/app/components/header/header.component.ts @@ -1,17 +1,17 @@ import { CommonModule } from "@angular/common"; -import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core"; +import { Component, OnDestroy } from "@angular/core"; import { ActivatedRoute, NavigationEnd, Router, RouterLink } from "@angular/router"; import { Subject, filter, takeUntil } 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 | null = null; +export class HeaderComponent implements OnDestroy { menuOpened = false; private destroy$ = new Subject(); constructor( @@ -27,13 +27,10 @@ export class HeaderComponent implements AfterViewInit, OnDestroy { .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 = ""; - } } }); } + changeMenu() { this.menuOpened = !this.menuOpened; } @@ -46,22 +43,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(); diff --git a/apps/NwaifuAnime/src/app/components/search-field/search-field.component.html b/apps/NwaifuAnime/src/app/components/search-field/search-field.component.html new file mode 100644 index 0000000..5447448 --- /dev/null +++ b/apps/NwaifuAnime/src/app/components/search-field/search-field.component.html @@ -0,0 +1,6 @@ +
+
+
+ +
+
diff --git a/apps/NwaifuAnime/src/app/components/search-field/search-field.component.less b/apps/NwaifuAnime/src/app/components/search-field/search-field.component.less new file mode 100644 index 0000000..e69de29 diff --git a/apps/NwaifuAnime/src/app/components/search-field/search-field.component.ts b/apps/NwaifuAnime/src/app/components/search-field/search-field.component.ts new file mode 100644 index 0000000..14d215b --- /dev/null +++ b/apps/NwaifuAnime/src/app/components/search-field/search-field.component.ts @@ -0,0 +1,42 @@ +import { CommonModule } from "@angular/common"; +import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core"; +import { ActivatedRoute, Router } from "@angular/router"; +import { Subject, 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 | null = null; + private destroy$ = new Subject(); + + 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; + } + }); + } + + search() { + if (this.searchInput && this.searchInput.nativeElement.value) + this.router.navigate(["/", "search"], { + queryParams: { search: this.searchInput.nativeElement.value }, + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } +}