From f426f5029b0c1549076b585b91ca1e5e37883dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20G=C3=B3reczny?= Date: Mon, 21 Dec 2020 16:54:22 +0100 Subject: [PATCH] Change to login to role --- .../ClientApp/src/app/app.module.ts | 2 +- .../components/sign-in/sign-in.component.ts | 19 ++++++++++++++----- .../src/app/store/models/app-state.model.ts | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts index 196d543..6bed2fc 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts @@ -54,7 +54,7 @@ BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }), MatSidenavModule, MatToolbarModule, MatListModule, - StoreModule.forRoot({app: AppReducer}), + StoreModule.forRoot({appState: AppReducer}), StoreDevtoolsModule.instrument({ logOnly: environment.production }) diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts index 3bfaec0..12a8f7f 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts @@ -8,6 +8,7 @@ import {HttpErrorResponse} from '@angular/common/http'; import {AppStoreModel} from '../../store/models/app-store.model'; import { Store } from '@ngrx/store'; import {AddUserId} from '../../store/actions/app.actions'; +import { AppState } from 'src/app/store/models/app-state.model'; @Component({ selector: 'app-sign-in', @@ -17,14 +18,14 @@ import {AddUserId} from '../../store/actions/app.actions'; export class SignInComponent implements OnDestroy, OnInit { allSubscriptions = new Subscription(); - role$: Observable; + role$: Observable; isExpanded = false; apiError = false; apiErrorMessage = ''; constructor(private router: Router, private formBuilder: FormBuilder, - private userService: UserService, private store: Store) { + private userService: UserService, private store: Store) { } public signInFormGroup: FormGroup = this.formBuilder.group({ @@ -37,18 +38,26 @@ export class SignInComponent implements OnDestroy, OnInit { }); ngOnInit() { - this.role$ = this.store.select('role'); + this.role$ = this.store.select(s => s.appState); } onLoginButtonClick() { - console.log(this.role$); + let role = ''; + this.store.select(s => s.appState.role).subscribe((v)=>{ + role = v; + }); this.allSubscriptions.add( this.userService.tryLogin( this.signInFormGroup.get('signIn').value['username'], this.signInFormGroup.get('signIn').value['password']).subscribe( (success) => { this.store.dispatch(new AddUserId({userId: success})); - this.router.navigate([this.role$]); + //TODO zmienić na jedna linie + if (role === 'player') { + this.router.navigate([role]); + } else { + this.router.navigate([role]); + } }, (error: ErrorResponse | HttpErrorResponse) => { if (error instanceof HttpErrorResponse) { diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/store/models/app-state.model.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/store/models/app-state.model.ts index 748e498..30226ba 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/store/models/app-state.model.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/store/models/app-state.model.ts @@ -1,5 +1,5 @@ import {AppStoreModel} from './app-store.model'; export interface AppState { - readonly player: AppStoreModel; + appState: AppStoreModel; }