Merge pull request #13761 from yuliaklochai/fix-trendz-settings

Fix Trendz settings not updating without page refresh
This commit is contained in:
Viacheslav Klimov 2025-07-24 16:07:37 +03:00 committed by GitHub
commit 452fe781c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import { Action } from '@ngrx/store';
import { AuthUser, User } from '@shared/models/user.model'; import { AuthUser, User } from '@shared/models/user.model';
import { AuthPayload } from '@core/auth/auth.models'; import { AuthPayload } from '@core/auth/auth.models';
import { UserSettings } from '@shared/models/user-settings.models'; import { UserSettings } from '@shared/models/user-settings.models';
import { TrendzSettings } from "@shared/models/trendz-settings.models";
export enum AuthActionTypes { export enum AuthActionTypes {
AUTHENTICATED = '[Auth] Authenticated', AUTHENTICATED = '[Auth] Authenticated',
@ -31,6 +32,7 @@ export enum AuthActionTypes {
UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section', UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section',
PUT_USER_SETTINGS = '[Preferences] Put user settings', PUT_USER_SETTINGS = '[Preferences] Put user settings',
DELETE_USER_SETTINGS = '[Preferences] Delete user settings', DELETE_USER_SETTINGS = '[Preferences] Delete user settings',
UPDATE_TRENDZ_SETTINGS = '[Auth] Update Trendz Settings',
} }
export class ActionAuthAuthenticated implements Action { export class ActionAuthAuthenticated implements Action {
@ -97,7 +99,13 @@ export class ActionPreferencesDeleteUserSettings implements Action {
constructor(readonly payload: Array<NestedKeyOf<UserSettings>>) {} constructor(readonly payload: Array<NestedKeyOf<UserSettings>>) {}
} }
export class ActionAuthUpdateTrendzSettings implements Action {
readonly type = AuthActionTypes.UPDATE_TRENDZ_SETTINGS;
constructor(readonly payload: TrendzSettings) {}
}
export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated | export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated |
ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository | ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository |
ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings | ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings |
ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled; ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled | ActionAuthUpdateTrendzSettings;

View File

@ -99,6 +99,9 @@ export const authReducer = (
action.payload.forEach(path => unset(userSettings, path)); action.payload.forEach(path => unset(userSettings, path));
return { ...state, ...{ userSettings }}; return { ...state, ...{ userSettings }};
case AuthActionTypes.UPDATE_TRENDZ_SETTINGS:
return { ...state, trendzSettings: action.payload };
default: default:
return state; return state;
} }

View File

@ -21,6 +21,9 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { TrendzSettingsService } from '@core/http/trendz-settings.service'; import { TrendzSettingsService } from '@core/http/trendz-settings.service';
import { TrendzSettings } from '@shared/models/trendz-settings.models'; import { TrendzSettings } from '@shared/models/trendz-settings.models';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; 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({ @Component({
selector: 'tb-trendz-settings', selector: 'tb-trendz-settings',
@ -31,7 +34,8 @@ export class TrendzSettingsComponent extends PageComponent implements OnInit, Ha
trendzSettingsForm: FormGroup; trendzSettingsForm: FormGroup;
constructor(private fb: FormBuilder, constructor(protected store: Store<AppState>,
private fb: FormBuilder,
private trendzSettingsService: TrendzSettingsService, private trendzSettingsService: TrendzSettingsService,
private destroyRef: DestroyRef) { private destroyRef: DestroyRef) {
super(); super();
@ -93,6 +97,7 @@ export class TrendzSettingsComponent extends PageComponent implements OnInit, Ha
this.trendzSettingsService.saveTrendzSettings(trendzSettings) this.trendzSettingsService.saveTrendzSettings(trendzSettings)
.subscribe(() => { .subscribe(() => {
this.setTrendzSettings(trendzSettings); this.setTrendzSettings(trendzSettings);
this.store.dispatch(new ActionAuthUpdateTrendzSettings(trendzSettings))
}) })
} }
} }