File size: 1,341 Bytes
1bc149f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {MatCard, MatCardHeader} from "@angular/material/card";
import {MatTab, MatTabGroup} from "@angular/material/tabs";
import {LeaderboardComponent} from "./leaderboard/leaderboard.component";
import {AppStateService} from "../../../state_management/services/app-state.service";
import {filter, map} from "rxjs";
import {AsyncPipe, NgForOf, NgIf} from "@angular/common";

@Component({
  selector: 'app-leaderboards',
  standalone: true,
  imports: [
    MatCard,
    MatCardHeader,
    MatTabGroup,
    MatTab,
    LeaderboardComponent,
    AsyncPipe,
    NgForOf,
    NgIf
  ],
  templateUrl: './leaderboards.component.html',
  styleUrl: './leaderboards.component.css'
})
export class LeaderboardsComponent implements OnChanges {

  @Input()
  task: string = '';

  @Input()
  showTask: boolean = true;

  datasets: any;

  constructor(
    private stateService: AppStateService
  ) {
    this.updateDatasets();
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (changes['task']) {
      this.updateDatasets();
    }
  }

  private updateDatasets() {
    this.datasets = this.stateService.state$.pipe(
      map(state =>
        state.datasets.filter(dataset =>
          dataset.task === this.task || !this.task
        )
      ),
    );
  }

}