UI: fixed Trendz settings update in AuthState
This commit is contained in:
		
							parent
							
								
									b7519718b3
								
							
						
					
					
						commit
						953c98106e
					
				@ -18,6 +18,7 @@ import { Action } from '@ngrx/store';
 | 
			
		||||
import { AuthUser, User } from '@shared/models/user.model';
 | 
			
		||||
import { AuthPayload } from '@core/auth/auth.models';
 | 
			
		||||
import { UserSettings } from '@shared/models/user-settings.models';
 | 
			
		||||
import { TrendzSettings } from "@shared/models/trendz-settings.models";
 | 
			
		||||
 | 
			
		||||
export enum AuthActionTypes {
 | 
			
		||||
  AUTHENTICATED = '[Auth] Authenticated',
 | 
			
		||||
@ -31,6 +32,7 @@ export enum AuthActionTypes {
 | 
			
		||||
  UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section',
 | 
			
		||||
  PUT_USER_SETTINGS = '[Preferences] Put user settings',
 | 
			
		||||
  DELETE_USER_SETTINGS = '[Preferences] Delete user settings',
 | 
			
		||||
  UPDATE_TRENDZ_SETTINGS = '[Auth] Update Trendz Settings',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class ActionAuthAuthenticated implements Action {
 | 
			
		||||
@ -97,7 +99,13 @@ export class ActionPreferencesDeleteUserSettings implements Action {
 | 
			
		||||
  constructor(readonly payload: Array<NestedKeyOf<UserSettings>>) {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class ActionAuthUpdateTrendzSettings implements Action {
 | 
			
		||||
  readonly type = AuthActionTypes.UPDATE_TRENDZ_SETTINGS;
 | 
			
		||||
 | 
			
		||||
  constructor(readonly payload: { trendzSettings: TrendzSettings }) {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated |
 | 
			
		||||
  ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository |
 | 
			
		||||
  ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings |
 | 
			
		||||
  ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled;
 | 
			
		||||
  ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled | ActionAuthUpdateTrendzSettings;
 | 
			
		||||
 | 
			
		||||
@ -99,6 +99,9 @@ export const authReducer = (
 | 
			
		||||
      action.payload.forEach(path => unset(userSettings, path));
 | 
			
		||||
      return { ...state, ...{ userSettings }};
 | 
			
		||||
 | 
			
		||||
    case AuthActionTypes.UPDATE_TRENDZ_SETTINGS:
 | 
			
		||||
      return { ...state, ...action.payload };
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      return state;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -21,6 +21,9 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
 | 
			
		||||
import { TrendzSettingsService } from '@core/http/trendz-settings.service';
 | 
			
		||||
import { TrendzSettings } from '@shared/models/trendz-settings.models';
 | 
			
		||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
 | 
			
		||||
import { Store } from "@ngrx/store";
 | 
			
		||||
import { AppState } from "@core/core.state";
 | 
			
		||||
import { ActionAuthUpdateTrendzSettings } from "@core/auth/auth.actions";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'tb-trendz-settings',
 | 
			
		||||
@ -31,7 +34,8 @@ export class TrendzSettingsComponent extends PageComponent implements OnInit, Ha
 | 
			
		||||
 | 
			
		||||
  trendzSettingsForm: FormGroup;
 | 
			
		||||
 | 
			
		||||
  constructor(private fb: FormBuilder,
 | 
			
		||||
  constructor(protected store: Store<AppState>,
 | 
			
		||||
              private fb: FormBuilder,
 | 
			
		||||
              private trendzSettingsService: TrendzSettingsService,
 | 
			
		||||
              private destroyRef: DestroyRef) {
 | 
			
		||||
    super();
 | 
			
		||||
@ -93,6 +97,7 @@ export class TrendzSettingsComponent extends PageComponent implements OnInit, Ha
 | 
			
		||||
    this.trendzSettingsService.saveTrendzSettings(trendzSettings)
 | 
			
		||||
      .subscribe(() => {
 | 
			
		||||
        this.setTrendzSettings(trendzSettings);
 | 
			
		||||
        this.store.dispatch(new ActionAuthUpdateTrendzSettings({ trendzSettings: trendzSettings}))
 | 
			
		||||
      })
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user