diff --git a/src/components/home/home.component.ts b/src/components/home/home.component.ts index 2e8af8d..ccc973d 100644 --- a/src/components/home/home.component.ts +++ b/src/components/home/home.component.ts @@ -1,5 +1,6 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { FormBuilder } from '@angular/forms'; +import { FormBuilder, FormGroup } from '@angular/forms'; + import { Champion } from 'src/models/champion'; import { Bonus } from 'src/models/bonus'; import { PoolService } from 'src/shared/pool.service'; @@ -7,6 +8,7 @@ import { PoolService } from 'src/shared/pool.service'; import { DomSanitizer } from '@angular/platform-browser'; import * as _ from 'lodash'; import { Subscription } from 'rxjs'; +import { DataToShare } from 'src/models/dataToShare'; @@ -17,13 +19,13 @@ import { Subscription } from 'rxjs'; }) export class HomeComponent implements OnInit, OnDestroy { - formFilters; + formFilters: FormGroup; bonusesPool: Bonus[] = []; champions: Champion[] = []; noChampSelected = true; - roles: [] = []; - rolesCount: [] = []; - rolesPool: [] = []; + roles: string[] = []; + rolesCount: number[] = []; + rolesPool: string[] = []; teamSize = 0; subscription: Subscription; @@ -33,7 +35,7 @@ export class HomeComponent implements OnInit, OnDestroy { private sanitizer: DomSanitizer, private poolService: PoolService ) { - this.subscription = this.poolService.setChampions().subscribe( data => { + this.subscription = this.poolService.setChampions().subscribe( (data: DataToShare) => { if (data) { const {champions, roles, rolesPool, bonusesPool, noChampSelected, teamSize } = data; this.champions = champions; diff --git a/src/models/dataToShare.ts b/src/models/dataToShare.ts new file mode 100644 index 0000000..ecf858b --- /dev/null +++ b/src/models/dataToShare.ts @@ -0,0 +1,14 @@ +import { Bonus } from './bonus'; +import { Champion } from './champion'; + +export class DataToShare { + constructor( + public champions: Champion[], + public roles: string[], + public rolesCount: number[], + public rolesPool: string[], + public bonusesPool: Bonus[], + public noChampSelected: boolean, + public teamSize: number + ) {} +} diff --git a/src/shared/pool.service.ts b/src/shared/pool.service.ts index 850783c..d4d81da 100644 --- a/src/shared/pool.service.ts +++ b/src/shared/pool.service.ts @@ -4,6 +4,7 @@ import { BehaviorSubject, Observable } from 'rxjs'; import { Constants } from 'src/shared/constants'; import { Bonus } from 'src/models/bonus'; import { Champion } from 'src/models/champion'; +import { DataToShare } from 'src/models/dataToShare'; import * as _ from 'lodash'; @@ -16,12 +17,12 @@ export class PoolService { champions: Champion[] = [...Constants.Champions]; championsPool: Champion[] = []; noChampSelected = true; - roles = [...Constants.roles]; - rolesCount = []; - rolesPool = []; + roles: string[]= [...Constants.roles]; + rolesCount: number[]= []; + rolesPool: string[] = []; selectedRole = ''; teamSize = 0; - dataToShare = new BehaviorSubject(null); + dataToShare = new BehaviorSubject(null); constructor() { } @@ -29,7 +30,7 @@ export class PoolService { * Set Champion pool and return data * @returns Observable */ - setChampions(): Observable { + setChampions(): Observable { this.roles.forEach(role => { this.rolesCount[role] = 0; }); @@ -38,7 +39,7 @@ export class PoolService { return this.dataToShare.asObservable(); } - updateDataToShare() { + updateDataToShare(): void { this.dataToShare.next({ champions: this.champions, roles: this.roles,