import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { MatDialog } from '@angular/material/dialog'; import { ApiService } from '../../services/api.service'; import { Season, SeasonWeek, SeasonStandingsEntry } from '../../models/season'; import { AuthService } from 'src/app/services/auth-service'; import { NewRaceDialogComponent } from '../new-race-dialog/new-race-dialog.component'; @Component({ selector: 'app-season-details', templateUrl: './season-details.component.html', styleUrls: ['./season-details.component.less'] }) export class SeasonDetailsComponent { seasonInfo?: Season; seasonStandings?: SeasonStandingsEntry[]; weeks?: SeasonWeek[]; newRaceDetails = { seasonId: '', mapName: '', mapImgUrl: '', startDate: '', endDate: '', }; constructor( private route: ActivatedRoute, private apiService: ApiService, private authService: AuthService, public dialog: MatDialog ) { } isAuthenticated: boolean = false; ngOnInit(): void { this.isAuthenticated = this.authService.isAuthenticated(); const id = String(this.route.snapshot.paramMap.get('id')); this.apiService.getSeasonDetails(id).subscribe(data => { this.seasonInfo = (data as any).season; this.weeks = (data as any).races; this.seasonStandings = (data as any).standings; console.log(data); console.log(this.seasonInfo); console.log(this.seasonStandings); console.log(this.weeks); }); } openNewRaceDialog(): void { if(this.seasonInfo) { this.newRaceDetails.seasonId = this.seasonInfo._id; } const dialogRef = this.dialog.open(NewRaceDialogComponent, { width: '400px', data: { ...this.newRaceDetails } }); dialogRef.afterClosed().subscribe(result => { if (result) { console.log('Follow details saved:', result); // You can update your data or perform other actions here } else { console.log('Dialog canceled'); } }); } }