feat: loading indication
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
<h1>It's home component</h1>
|
<h1>It's home component</h1>
|
||||||
<div class="flex flex-col items-center w-full px-3">
|
<div class="flex flex-col items-center w-full px-3">
|
||||||
|
@if (loading) {
|
||||||
|
<h1>Loading...</h1>
|
||||||
|
}
|
||||||
|
@if (notFound && !loading) {
|
||||||
|
<h1>Not found</h1>
|
||||||
|
}
|
||||||
@for (item of items; track $index) {
|
@for (item of items; track $index) {
|
||||||
<a
|
<a
|
||||||
routerLink="/detail"
|
routerLink="/detail"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { AfterViewInit, Component, Input, OnDestroy } from "@angular/core";
|
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
||||||
import { ActivatedRoute, RouterLink } from "@angular/router";
|
import { ActivatedRoute, RouterLink } from "@angular/router";
|
||||||
import { Subject, takeUntil } from "rxjs";
|
import { Subject, takeUntil } from "rxjs";
|
||||||
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
||||||
@@ -12,8 +12,10 @@ import { SearchService } from "../../services/search.service";
|
|||||||
styleUrls: ["./home.component.less"],
|
styleUrls: ["./home.component.less"],
|
||||||
imports: [CommonModule, RouterLink],
|
imports: [CommonModule, RouterLink],
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnDestroy, AfterViewInit {
|
export class HomeComponent implements OnDestroy, OnInit {
|
||||||
@Input() items: Datum[] = [];
|
@Input() items: Datum[] = [];
|
||||||
|
loading = false;
|
||||||
|
notFound = false;
|
||||||
|
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
@@ -27,15 +29,18 @@ export class HomeComponent implements OnDestroy, AfterViewInit {
|
|||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.queryParams.subscribe((params) => {
|
this.route.queryParams.subscribe((params) => {
|
||||||
const search = params["search"];
|
const search = params["search"];
|
||||||
if (search) {
|
if (search) {
|
||||||
|
this.loading = true;
|
||||||
this.searchService
|
this.searchService
|
||||||
.search(search)
|
.search(search)
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe((data) => {
|
.subscribe((data) => {
|
||||||
|
this.loading = false;
|
||||||
this.items = data.data;
|
this.items = data.data;
|
||||||
|
this.notFound = this.items.length === 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user