feat: add loading indicators for users and todos
This commit is contained in:
@ -20,18 +20,23 @@ export class AppComponent {
|
||||
users: WritableSignal<any[]> = signal([]);
|
||||
|
||||
todos: WritableSignal<any[]> = signal([]);
|
||||
|
||||
isLoadingUsers = signal(true);
|
||||
isLoadingTodos = signal(false);
|
||||
|
||||
ngOnInit() {
|
||||
this.userService.getUsers().subscribe(users => this.users.set(users));
|
||||
|
||||
if(this.selectedUserId() !== null) {
|
||||
this.userService.getTodos(this.selectedUserId()!).subscribe(todos => this.todos.set(todos));
|
||||
}
|
||||
this.userService.getUsers().subscribe(users => {
|
||||
this.users.set(users);
|
||||
});
|
||||
}
|
||||
|
||||
onUserSelect(event: Event) {
|
||||
this.isLoadingTodos.set(true)
|
||||
const userId = Number((event.target as HTMLSelectElement).value);
|
||||
this.selectedUserId.set(userId);
|
||||
this.userService.getTodos(userId).subscribe(todos => this.todos.set(todos));
|
||||
this.userService.getTodos(userId).subscribe(todos => {
|
||||
this.todos.set(todos)
|
||||
this.isLoadingTodos.set(false)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user