feat: started details page
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
@if (detail_item) {
|
||||
<h1>{{ detail_item.name }}</h1>
|
||||
<h2>{{ detail_item.rus_name }}</h2>
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { Data } from "../../services/parsers/rulib/rulib.detail.dto";
|
||||
import { SearchService } from "../../services/search.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-detail",
|
||||
templateUrl: "./detail.component.html",
|
||||
styleUrls: ["./detail.component.less"],
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class DetailComponent implements AfterViewInit {
|
||||
detail_item: Data | null = null;
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private searchService: SearchService,
|
||||
private router: Router,
|
||||
) {}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const url = params["url"];
|
||||
if (url) {
|
||||
this.searchService.getDetails(url).subscribe((data) => (this.detail_item = data.data));
|
||||
} else {
|
||||
this.router.navigate(["/"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
class="header fixed flex justify-between w-full p-2 bg-gray-700 md:h-8 h-auto items-center md:flex-row flex-col md:gap-0 gap-3"
|
||||
>
|
||||
<div class="flex justify-between flex-row w-full align-middle">
|
||||
<h1 class="text-white">NwaifuAnime</h1>
|
||||
<a href="/"><h1 class="text-white">NwaifuAnime</h1></a>
|
||||
<!-- Search bar on small screens -->
|
||||
<button type="button" class="md:hidden" (click)="changeMenu()">
|
||||
<i [class]="menuBtnClass"></i>
|
||||
@@ -15,6 +15,7 @@
|
||||
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()"
|
||||
/>
|
||||
<button class="align-middle w-[100px] text-center" type="submit" (click)="search()">
|
||||
<span class="text-sm text-black h-full">Поиск</span>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, ElementRef, EventEmitter, Output, ViewChild } from "@angular/core";
|
||||
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: "app-header",
|
||||
@@ -8,10 +9,13 @@ import { Component, ElementRef, EventEmitter, Output, ViewChild } from "@angular
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class HeaderComponent {
|
||||
@Output() searchEvent: EventEmitter<string> = new EventEmitter();
|
||||
export class HeaderComponent implements AfterViewInit {
|
||||
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
|
||||
menuOpened = false;
|
||||
constructor(
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
) {}
|
||||
changeMenu() {
|
||||
this.menuOpened = !this.menuOpened;
|
||||
}
|
||||
@@ -27,7 +31,16 @@ export class HeaderComponent {
|
||||
search() {
|
||||
if (this.searchInput) {
|
||||
const text = this.searchInput.nativeElement.value;
|
||||
this.searchEvent.emit(text);
|
||||
this.router.navigateByUrl(`/?search=${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const search = params["search"];
|
||||
if (search && this.searchInput) {
|
||||
this.searchInput.nativeElement.value = search;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
||||
import { AfterViewInit, Component, Input, OnDestroy, OnInit } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { Subscription } from "rxjs";
|
||||
import { Datum } from "../../services/parsers/rulib/rulib.dto";
|
||||
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
||||
import { SearchService } from "../../services/search.service";
|
||||
|
||||
@Component({
|
||||
@@ -11,11 +12,15 @@ import { SearchService } from "../../services/search.service";
|
||||
styleUrls: ["./home.component.less"],
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class HomeComponent implements OnInit, OnDestroy {
|
||||
export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
@Input() items: Datum[] = [];
|
||||
private subscription: Subscription = new Subscription();
|
||||
|
||||
constructor(private searchService: SearchService) {}
|
||||
constructor(
|
||||
private searchService: SearchService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.searchService.currentItemsTerm.subscribe((data) => {
|
||||
@@ -24,12 +29,20 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
getDetails(slug_url: string) {
|
||||
this.searchService.getDetails(slug_url).subscribe((data) => {
|
||||
console.log(data);
|
||||
});
|
||||
this.router.navigate(["/", "detail"], { queryParams: { url: slug_url } });
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const search = params["search"];
|
||||
console.log(params);
|
||||
if (search) {
|
||||
this.searchService.search(search);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user