import {Component, OnInit} from '@angular/core'; import {userType} from '../../models/User'; import {AuthService} from '../../services/auth.service'; import {Router} from '@angular/router'; import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; import {UsersService} from '../../services/users.service'; import {firstValueFrom} from 'rxjs'; @Component({ selector: 'app-dashboard', standalone: false, templateUrl: './dashboard.component.html', styleUrl: './dashboard.component.css' }) export class DashboardComponent implements OnInit{ topNeeds?: Need[] almostThere?: Need[] inBasket?: Need[] constructor( protected authService: AuthService, protected router: Router, protected cupboardService: CupboardService ) {} ngOnInit() { let user = this.authService.getCurrentUser() if(!user) { this.router.navigate(['/login']) return } firstValueFrom(this.cupboardService.getNeeds()).then(r => { this.topNeeds = r.sort((a, b) => b.current - a.current) this.almostThere = r.sort((a, b) => a.current/a.maxGoal - b.current/b.maxGoal) this.inBasket = r.filter(n => n.id in user?.basket) }) } }