SES-123 Added reducers and miissed unsubscribe

This commit is contained in:
Łukasz Góreczny 2020-12-27 17:55:28 +01:00
parent b82393a62b
commit e17e3ace58
3 changed files with 14 additions and 8 deletions

View File

@ -23,9 +23,9 @@ import {
import {UserService} from '../services/user.service'; import {UserService} from '../services/user.service';
import { StoreModule } from '@ngrx/store'; import { StoreModule } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools'; import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import {AppReducer} from './store/reducers/app.reducer';
import {environment} from '../environments/environment'; import {environment} from '../environments/environment';
import {SessionCompanionIconsModule} from './shared/sc-icons/session-companion-icons.module'; import {SessionCompanionIconsModule} from './shared/sc-icons/session-companion-icons.module';
import {reducers} from './store/models/app-state.model';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -55,7 +55,7 @@ BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
MatToolbarModule, MatToolbarModule,
MatListModule, MatListModule,
SessionCompanionIconsModule, SessionCompanionIconsModule,
StoreModule.forRoot({appState: AppReducer}), StoreModule.forRoot(reducers),
StoreDevtoolsModule.instrument({ StoreDevtoolsModule.instrument({
logOnly: environment.production logOnly: environment.production
}) })

View File

@ -6,9 +6,9 @@ import {ErrorResponse} from '../../../types/ErrorResponse';
import {Observable, Subscription} from 'rxjs'; import {Observable, Subscription} from 'rxjs';
import {HttpErrorResponse} from '@angular/common/http'; import {HttpErrorResponse} from '@angular/common/http';
import {AppStoreModel} from '../../store/models/app-store.model'; import {AppStoreModel} from '../../store/models/app-store.model';
import { Store } from '@ngrx/store'; import {select, Store} from '@ngrx/store';
import {AddUserId} from '../../store/actions/app.actions'; import {AddUserId} from '../../store/actions/app.actions';
import { AppState } from 'src/app/store/models/app-state.model'; import {AppState} from 'src/app/store/models/app-state.model';
@Component({ @Component({
selector: 'app-sign-in', selector: 'app-sign-in',
@ -38,14 +38,14 @@ export class SignInComponent implements OnDestroy, OnInit {
}); });
ngOnInit() { ngOnInit() {
this.role$ = this.store.select(s => s.appState); this.role$ = this.store.select(s => s.appStore);
} }
onLoginButtonClick() { onLoginButtonClick() {
let role = ''; let role = '';
this.store.select(s => s.appState.role).subscribe((v) => { this.store.select(s => s.appStore.role).subscribe((v) => {
role = v; role = v;
}); }).unsubscribe();
this.allSubscriptions.add( this.allSubscriptions.add(
this.userService.tryLogin( this.userService.tryLogin(
this.signInFormGroup.get('signIn').value['username'], this.signInFormGroup.get('signIn').value['username'],

View File

@ -1,5 +1,11 @@
import {AppStoreModel} from './app-store.model'; import {AppStoreModel} from './app-store.model';
import {ActionReducerMap} from '@ngrx/store';
import {AppReducer} from '../reducers/app.reducer';
export interface AppState { export interface AppState {
appState: AppStoreModel; appStore: AppStoreModel;
} }
export const reducers: ActionReducerMap<AppState> = {
appStore: AppReducer,
};