import { CommonModule } from "@angular/common"; import { AfterViewInit, Component, Input, OnDestroy } from "@angular/core"; import { ActivatedRoute, RouterLink } from "@angular/router"; import { Subject, takeUntil } from "rxjs"; import { Datum } from "../../services/parsers/rulib/rulib.search.dto"; import { SearchService } from "../../services/search.service"; @Component({ standalone: true, selector: "app-home", templateUrl: "./home.component.html", styleUrls: ["./home.component.less"], imports: [CommonModule, RouterLink], }) export class HomeComponent implements OnDestroy, AfterViewInit { @Input() items: Datum[] = []; private destroy$ = new Subject(); constructor( private searchService: SearchService, private route: ActivatedRoute, ) {} ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); } ngAfterViewInit(): void { this.route.queryParams.subscribe((params) => { const search = params["search"]; if (search) { this.searchService .search(search) .pipe(takeUntil(this.destroy$)) .subscribe((data) => { this.items = data.data; }); } }); } }