Browse Source

Merge pull request #10623 from vvlladd28/fixed/transltion/load

Improved detect auth user in load
pull/10635/head
Igor Kulikov 2 years ago
committed by GitHub
parent
commit
d56d85d81c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 15
      ui-ngx/src/app/app.component.ts
  2. 6
      ui-ngx/src/app/core/auth/auth.selectors.ts
  3. 4
      ui-ngx/src/app/core/auth/auth.service.ts
  4. 17
      ui-ngx/src/app/shared/components/json-content.component.ts

15
ui-ngx/src/app/app.component.ts

@ -21,17 +21,15 @@ import { Component, OnInit } from '@angular/core';
import { environment as env } from '@env/environment';
import { TranslateService } from '@ngx-translate/core';
import { select, Store } from '@ngrx/store';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { LocalStorageService } from '@core/local-storage/local-storage.service';
import { DomSanitizer } from '@angular/platform-browser';
import { MatIconRegistry } from '@angular/material/icon';
import { combineLatest } from 'rxjs';
import { getCurrentAuthState, selectIsAuthenticated, selectIsUserLoaded } from '@core/auth/auth.selectors';
import { distinctUntilChanged, filter, map, skip, tap } from 'rxjs/operators';
import { getCurrentAuthState, selectUserReady } from '@core/auth/auth.selectors';
import { filter, skip, tap } from 'rxjs/operators';
import { AuthService } from '@core/auth/auth.service';
import { svgIcons, svgIconsUrl } from '@shared/models/icon.models';
import { isEqual } from '@core/utils';
import { ActionSettingsChangeLanguage } from '@core/settings/settings.actions';
import { SETTINGS_KEY } from '@core/settings/settings.effects';
@ -90,13 +88,8 @@ export class AppComponent implements OnInit {
}
setupAuth() {
combineLatest([
this.store.pipe(select(selectIsAuthenticated)),
this.store.pipe(select(selectIsUserLoaded))]
).pipe(
map(results => ({isAuthenticated: results[0], isUserLoaded: results[1]})),
this.store.select(selectUserReady).pipe(
filter((data) => data.isUserLoaded),
distinctUntilChanged((a, b) => isEqual(a, b)),
tap((data) => {
let userLang = getCurrentAuthState(this.store).userDetails?.additionalInfo?.lang ?? null;
if (!userLang && !data.isAuthenticated) {

6
ui-ngx/src/app/core/auth/auth.selectors.ts

@ -42,6 +42,12 @@ export const selectIsUserLoaded = createSelector(
(state: AuthState) => state.isUserLoaded
);
export const selectUserReady = createSelector(
selectIsAuthenticated,
selectIsUserLoaded,
(isAuthenticated, isUserLoaded) => ({isAuthenticated, isUserLoaded})
);
export const selectAuthUser = createSelector(
selectAuthState,
(state: AuthState) => state.authUser

4
ui-ngx/src/app/core/auth/auth.service.ts

@ -546,14 +546,14 @@ export class AuthService {
this.notifyUserLoaded(false);
this.loadUser(false).subscribe(
(authPayload) => {
this.notifyUserLoaded(true);
this.notifyAuthenticated(authPayload);
this.notifyUserLoaded(true);
authenticatedSubject.next(true);
authenticatedSubject.complete();
},
() => {
this.notifyUserLoaded(true);
this.notifyUnauthenticated();
this.notifyUserLoaded(true);
authenticatedSubject.next(false);
authenticatedSubject.complete();
}

17
ui-ngx/src/app/shared/components/json-content.component.ts

@ -18,13 +18,11 @@ import {
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
forwardRef,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
ViewChild,
ViewEncapsulation
@ -104,9 +102,6 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
@coerceBoolean()
required: boolean;
@Output()
blur: EventEmitter<void> = new EventEmitter<void>();
fullscreen = false;
contentBody: string;
@ -116,7 +111,6 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
errorShowed = false;
private propagateChange = null;
private onTouched = () => {};
constructor(public elementRef: ElementRef,
protected store: Store<AppState>,
@ -156,14 +150,12 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
this.updateView();
}
});
this.jsonEditor.on('blur', () => {
if (this.validateContent) {
if (this.validateContent) {
this.jsonEditor.on('blur', () => {
this.contentValid = this.doValidate(true);
this.cd.markForCheck();
}
this.onTouched();
this.blur.next();
});
});
}
if (this.tbPlaceholder && this.tbPlaceholder.length) {
this.createPlaceholder();
@ -251,7 +243,6 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
}
registerOnTouched(fn: any): void {
this.onTouched = fn;
}
setDisabledState(isDisabled: boolean): void {

Loading…
Cancel
Save