connected with backend - select character
This commit is contained in:
parent
665ef65ec0
commit
18d1b75c4a
@ -6,7 +6,7 @@
|
|||||||
<mat-list-item *ngFor="let character of charactersList">
|
<mat-list-item *ngFor="let character of charactersList">
|
||||||
<mat-icon mat-list-icon>account_circle</mat-icon>
|
<mat-icon mat-list-icon>account_circle</mat-icon>
|
||||||
<div mat-line>{{character.name}}</div>
|
<div mat-line>{{character.name}}</div>
|
||||||
<mat-icon matSuffix class="arrow-forward arrow-select" (click)="onCharacterClick()">arrow_forward</mat-icon>
|
<mat-icon matSuffix class="arrow-forward arrow-select" (click)="onCharacterClick(character.id)">arrow_forward</mat-icon>
|
||||||
<div mat-line> {{character.className}} level: {{character.level}}</div>
|
<div mat-line> {{character.className}} level: {{character.level}}</div>
|
||||||
<mat-divider></mat-divider>
|
<mat-divider></mat-divider>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
|
@ -8,6 +8,7 @@ import {Store} from "@ngrx/store";
|
|||||||
import {AppState} from "../../store/models/app-state.model";
|
import {AppState} from "../../store/models/app-state.model";
|
||||||
import {CharacterService} from "../../../services/character.service";
|
import {CharacterService} from "../../../services/character.service";
|
||||||
import {CharacterForLoginViewModel} from "../../../types/viewmodels/character-viewmodels/CharacterForLoginViewModel";
|
import {CharacterForLoginViewModel} from "../../../types/viewmodels/character-viewmodels/CharacterForLoginViewModel";
|
||||||
|
import {AddCharacterId} from "../../store/actions/player.action";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-select-character',
|
selector: 'app-select-character',
|
||||||
@ -36,7 +37,8 @@ export class SelectCharacterComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCharacterClick(){
|
onCharacterClick(characterId: number){
|
||||||
|
this.store.dispatch(new AddCharacterId({characterId}))
|
||||||
this.router.navigate(['player'])
|
this.router.navigate(['player'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import {AppStoreModel} from '../models/app-store.model';
|
|
||||||
import {Action} from '@ngrx/store';
|
import {Action} from '@ngrx/store';
|
||||||
|
|
||||||
export enum AppActionTypes {
|
export enum AppActionTypes {
|
||||||
@ -26,7 +25,8 @@ export class ClearUserId implements Action {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type AppAction = AddUserId | AddRole | ClearUserId;
|
export type AppAction = AddUserId | AddRole | ClearUserId;
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
import {Action} from "@ngrx/store";
|
||||||
|
|
||||||
|
export enum PlayerActionTypes {
|
||||||
|
ADD_CHARACTER_ID= '[PLAYER] Add character id'
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AddCharacterId implements Action {
|
||||||
|
readonly type = PlayerActionTypes.ADD_CHARACTER_ID;
|
||||||
|
|
||||||
|
constructor(public payload: {characterId: number}) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PlayerAction = AddCharacterId;
|
@ -1,11 +1,15 @@
|
|||||||
import {AppStoreModel} from './app-store.model';
|
import {AppStoreModel} from './app-store.model';
|
||||||
import {ActionReducerMap} from '@ngrx/store';
|
import {ActionReducerMap} from '@ngrx/store';
|
||||||
import {AppReducer} from '../reducers/app.reducer';
|
import {AppReducer} from '../reducers/app.reducer';
|
||||||
|
import {PlayerStoreModel} from "./player-store.model";
|
||||||
|
import {PlayerReducer} from "../reducers/player.reducer";
|
||||||
|
|
||||||
export interface AppState {
|
export interface AppState {
|
||||||
appStore: AppStoreModel;
|
appStore: AppStoreModel;
|
||||||
|
playerStore: PlayerStoreModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const reducers: ActionReducerMap<AppState> = {
|
export const reducers: ActionReducerMap<AppState> = {
|
||||||
appStore: AppReducer,
|
appStore: AppReducer,
|
||||||
|
playerStore: PlayerReducer,
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
export interface PlayerStoreModel {
|
||||||
|
characterId: number;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import {PlayerStoreModel} from "../models/player-store.model";
|
||||||
|
import {PlayerAction, PlayerActionTypes} from "../actions/player.action";
|
||||||
|
|
||||||
|
const initialState: PlayerStoreModel = {
|
||||||
|
characterId: null
|
||||||
|
};
|
||||||
|
|
||||||
|
export function PlayerReducer(state: PlayerStoreModel = initialState, action: PlayerAction) {
|
||||||
|
switch (action.type) {
|
||||||
|
case PlayerActionTypes.ADD_CHARACTER_ID:
|
||||||
|
return {...state, characterId: action.payload.characterId};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user