Change to login to role
This commit is contained in:
parent
b49bdae96a
commit
f426f5029b
@ -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
|
||||
})
|
||||
|
@ -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<string>;
|
||||
role$: Observable<AppStoreModel>;
|
||||
|
||||
isExpanded = false;
|
||||
apiError = false;
|
||||
apiErrorMessage = '';
|
||||
|
||||
constructor(private router: Router, private formBuilder: FormBuilder,
|
||||
private userService: UserService, private store: Store<AppStoreModel>) {
|
||||
private userService: UserService, private store: Store<AppState>) {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {AppStoreModel} from './app-store.model';
|
||||
|
||||
export interface AppState {
|
||||
readonly player: AppStoreModel;
|
||||
appState: AppStoreModel;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user