refactor(app): improve loading state management in user fetch
This commit is contained in:
@ -27,16 +27,18 @@ export class AppComponent {
|
||||
ngOnInit() {
|
||||
this.userService.getUsers().subscribe(users => {
|
||||
this.users.set(users);
|
||||
this.isLoadingUsers.set(false)
|
||||
});
|
||||
}
|
||||
|
||||
onUserSelect(event: Event) {
|
||||
this.isLoadingTodos.set(true)
|
||||
onUserSelect(event: Event): void {
|
||||
const userId = Number((event.target as HTMLSelectElement).value);
|
||||
this.selectedUserId.set(userId);
|
||||
this.userService.getTodos(userId).subscribe(todos => {
|
||||
this.todos.set(todos)
|
||||
this.isLoadingTodos.set(false)
|
||||
this.isLoadingTodos.set(true);
|
||||
this.userService.getTodos(userId).subscribe({
|
||||
next: (todos) => this.todos.set(todos),
|
||||
error: () => this.isLoadingTodos.set(false),
|
||||
complete: () => this.isLoadingTodos.set(false)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { delay, Observable, shareReplay } from 'rxjs';
|
||||
import { delay, Observable } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
Reference in New Issue
Block a user