From 2660aef4734ad67b688872b91932f5e87e59364f Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Fri, 5 Jul 2024 20:07:13 +0300 Subject: [PATCH] feat: started details page --- apps/NwaifuAnime/src/app/app.component.html | 2 +- apps/NwaifuAnime/src/app/app.component.ts | 33 ++------- apps/NwaifuAnime/src/app/app.routes.ts | 2 + .../components/detail/detail.component.html | 4 ++ .../components/detail/detail.component.less | 0 .../app/components/detail/detail.component.ts | 32 +++++++++ .../components/header/header.component.html | 3 +- .../app/components/header/header.component.ts | 21 ++++-- .../src/app/components/home/home.component.ts | 27 ++++++-- .../rulib/lib.social.parser.service.ts | 7 +- .../parsers/rulib/rulib.detail.dto.ts | 69 +++++++++++++++++++ .../{rulib.dto.ts => rulib.search.dto.ts} | 0 .../src/app/services/search.service.ts | 5 +- 13 files changed, 159 insertions(+), 46 deletions(-) create mode 100644 apps/NwaifuAnime/src/app/components/detail/detail.component.html create mode 100644 apps/NwaifuAnime/src/app/components/detail/detail.component.less create mode 100644 apps/NwaifuAnime/src/app/components/detail/detail.component.ts create mode 100644 apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.detail.dto.ts rename apps/NwaifuAnime/src/app/services/parsers/rulib/{rulib.dto.ts => rulib.search.dto.ts} (100%) diff --git a/apps/NwaifuAnime/src/app/app.component.html b/apps/NwaifuAnime/src/app/app.component.html index e419ca1..fc8bdc9 100644 --- a/apps/NwaifuAnime/src/app/app.component.html +++ b/apps/NwaifuAnime/src/app/app.component.html @@ -6,6 +6,6 @@

Update not available

} } - +
diff --git a/apps/NwaifuAnime/src/app/app.component.ts b/apps/NwaifuAnime/src/app/app.component.ts index 292517b..c57fac1 100644 --- a/apps/NwaifuAnime/src/app/app.component.ts +++ b/apps/NwaifuAnime/src/app/app.component.ts @@ -1,9 +1,8 @@ -import { AfterViewInit, Component } from "@angular/core"; -import { ActivatedRoute, Router, RouterModule } from "@angular/router"; +import { Component } from "@angular/core"; +import { RouterModule } from "@angular/router"; import { AppService } from "./app.service"; import { HeaderComponent } from "./components/header/header.component"; -import { Datum } from "./services/parsers/rulib/rulib.dto"; -import { SearchService } from "./services/search.service"; +import { Datum } from "./services/parsers/rulib/rulib.search.dto"; @Component({ standalone: true, @@ -13,15 +12,10 @@ import { SearchService } from "./services/search.service"; styleUrl: "./app.component.less", providers: [AppService], }) -export class AppComponent implements AfterViewInit { +export class AppComponent { title = "NwaifuAnime"; items: Datum[] = []; - constructor( - private sw: AppService, - private searchService: SearchService, - private route: ActivatedRoute, - private router: Router, - ) {} + constructor(private sw: AppService) {} get hasUpdate() { return this.sw.isUpdateAvailable; @@ -34,21 +28,4 @@ export class AppComponent implements AfterViewInit { get serviceWorkerEnabled() { return this.sw.serviceWorkerEnabled; } - - onSearch(text: string) { - const currentParams = this.route.snapshot.queryParams; - const newParams = { ...currentParams, search: text }; - this.router.navigate([], { queryParams: newParams }); - this.searchService.search(text); - } - - ngAfterViewInit(): void { - this.route.queryParams.subscribe((params) => { - console.log(params); - const searchParam: string | undefined = params["search"]; - if (searchParam) { - this.searchService.search(searchParam); - } - }); - } } diff --git a/apps/NwaifuAnime/src/app/app.routes.ts b/apps/NwaifuAnime/src/app/app.routes.ts index 814f55a..c92235c 100644 --- a/apps/NwaifuAnime/src/app/app.routes.ts +++ b/apps/NwaifuAnime/src/app/app.routes.ts @@ -1,4 +1,5 @@ import { Route } from "@angular/router"; +import { DetailComponent } from "./components/detail/detail.component"; import { HomeComponent } from "./components/home/home.component"; export const appRoutes: Route[] = [ @@ -6,4 +7,5 @@ export const appRoutes: Route[] = [ path: "", component: HomeComponent, }, + { path: "detail", component: DetailComponent }, ]; diff --git a/apps/NwaifuAnime/src/app/components/detail/detail.component.html b/apps/NwaifuAnime/src/app/components/detail/detail.component.html new file mode 100644 index 0000000..eab7076 --- /dev/null +++ b/apps/NwaifuAnime/src/app/components/detail/detail.component.html @@ -0,0 +1,4 @@ +@if (detail_item) { +

{{ detail_item.name }}

+

{{ detail_item.rus_name }}

+} diff --git a/apps/NwaifuAnime/src/app/components/detail/detail.component.less b/apps/NwaifuAnime/src/app/components/detail/detail.component.less new file mode 100644 index 0000000..e69de29 diff --git a/apps/NwaifuAnime/src/app/components/detail/detail.component.ts b/apps/NwaifuAnime/src/app/components/detail/detail.component.ts new file mode 100644 index 0000000..1e2e640 --- /dev/null +++ b/apps/NwaifuAnime/src/app/components/detail/detail.component.ts @@ -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(["/"]); + } + }); + } +} diff --git a/apps/NwaifuAnime/src/app/components/header/header.component.html b/apps/NwaifuAnime/src/app/components/header/header.component.html index b81e4c6..eeb7895 100644 --- a/apps/NwaifuAnime/src/app/components/header/header.component.html +++ b/apps/NwaifuAnime/src/app/components/header/header.component.html @@ -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" >
-

NwaifuAnime

+

NwaifuAnime