import {Component, OnInit} from '@angular/core'; import {Task} from "../../Interfaces/task.interface"; import {ApiService} from "../../Services/api.service"; import {ActivatedRoute, Router} from "@angular/router"; @Component({ selector: 'app-blue', templateUrl: './blue.component.html', styleUrls: ['./blue.component.scss'] }) export class BlueComponent implements OnInit{ tasks: Task[] = []; task!: Task; index: string; loading: boolean = true; constructor(private apiService: ApiService, private activeRoute: ActivatedRoute, private router: Router) { this.index = this.activeRoute.snapshot.paramMap.get('id') ?? ''; } ngOnInit(): void { this.apiService.getTodaysTasks().subscribe({ next: (tasks: Task[]): void=>{ tasks.forEach((task: Task): void=>{ if(task.type === "blue"){ this.tasks.push(task) } }) this.loading = false this.task = this.tasks[+this.index] if(this.task === undefined){ this.router.navigate(["/home"]) } }, error: (): void=>{ this.router.navigate(["/home"]) } }) } }