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

View File

@ -6,7 +6,7 @@ import {ErrorResponse} from '../../../types/ErrorResponse';
import {Observable, Subscription} from 'rxjs';
import {HttpErrorResponse} from '@angular/common/http';
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 {AppState} from 'src/app/store/models/app-state.model';
@ -38,14 +38,14 @@ export class SignInComponent implements OnDestroy, OnInit {
});
ngOnInit() {
this.role$ = this.store.select(s => s.appState);
this.role$ = this.store.select(s => s.appStore);
}
onLoginButtonClick() {
let role = '';
this.store.select(s => s.appState.role).subscribe((v) => {
this.store.select(s => s.appStore.role).subscribe((v) => {
role = v;
});
}).unsubscribe();
this.allSubscriptions.add(
this.userService.tryLogin(
this.signInFormGroup.get('signIn').value['username'],

View File

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