SES-135 abilities card #63
@ -1,14 +1,28 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { AbilityViewModel } from "../../../types/viewmodels/ability-viewmodels/AbilityViewModel";
|
||||
import {AppState} from "../../store/models/app-state.model";
|
||||
import {Store} from "@ngrx/store";
|
||||
import {first} from "rxjs/operators";
|
||||
import {CharacterService} from "../../../services/character.service";
|
||||
import {CharacterStatsViewModel} from "../../../types/viewmodels/character-viewmodels/CharacterStatsViewModel";
|
||||
import {ErrorResponse} from "../../../types/ErrorResponse";
|
||||
import {HttpErrorResponse} from "@angular/common/http";
|
||||
|
||||
@Component({
|
||||
selector: 'app-player-dashboard',
|
||||
templateUrl: './player-dashboard.component.html',
|
||||
styleUrls: ['./player-dashboard.component.css'],
|
||||
})
|
||||
export class PlayerDashboardComponent {
|
||||
export class PlayerDashboardComponent implements OnInit {
|
||||
isExpanded = false;
|
||||
selected = false;
|
||||
characterStats: CharacterStatsViewModel[];
|
||||
|
||||
constructor(private store: Store<AppState>, private characterService: CharacterService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.getCharacterStats();
|
||||
}
|
||||
|
||||
ability: AbilityViewModel = {
|
||||
id: 1,
|
||||
@ -26,11 +40,21 @@ export class PlayerDashboardComponent {
|
||||
]
|
||||
}
|
||||
|
||||
collapse() {
|
||||
this.isExpanded = false;
|
||||
getCharacterStats() {
|
||||
this.store.select( s => s.playerStore.characterId).pipe(first()).subscribe((characterId) => {
|
||||
this.characterService.getCharacterStats(characterId).pipe(first()).subscribe((characterStats) => {
|
||||
this.characterStats = characterStats;
|
||||
}, (error: ErrorResponse | HttpErrorResponse) => {
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
error = error.error as ErrorResponse;
|
||||
}
|
||||
console.error(error.message);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.isExpanded = !this.isExpanded;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import {Either} from '../types/Either';
|
||||
import {CharacterForLoginViewModel} from '../types/viewmodels/character-viewmodels/CharacterForLoginViewModel';
|
||||
import {switchMap, retry} from 'rxjs/operators';
|
||||
import {LoggedCharactersViewModel} from '../types/viewmodels/character-viewmodels/LoggedCharactersViewModel';
|
||||
import {CharacterStatsViewModel} from "../types/viewmodels/character-viewmodels/CharacterStatsViewModel";
|
||||
|
||||
Injectable({
|
||||
providedIn: 'root'
|
||||
@ -41,4 +42,18 @@ export class CharacterService {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getCharacterStats(characterId: number): Observable<CharacterStatsViewModel[]> {
|
||||
const params = new HttpParams().set('characterId', characterId.toString())
|
||||
return this.http.get<Either<CharacterStatsViewModel[], ErrorResponse>>( this.baseUrl + 'characterStats', {params}).pipe(
|
||||
switchMap( response => {
|
||||
if (response.isLeft) {
|
||||
return of(response.left);
|
||||
} else {
|
||||
return throwError(response.right);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
export interface CharacterStatsViewModel {
|
||||
id: number;
|
||||
name: string;
|
||||
value: number;
|
||||
modification: number;
|
||||
savingThrows: number;
|
||||
canSaveThrows: boolean;
|
||||
skills: {
|
||||
name: string;
|
||||
value: number;
|
||||
can: boolean;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user