[DURACOM-288] Refactoring configuration to transfer state

This commit is contained in:
Giuseppe Digilio
2025-01-09 18:46:22 +01:00
parent a7276b8a30
commit cfba84ce31
9 changed files with 45 additions and 26 deletions

View File

@@ -21,7 +21,10 @@ import { LocaleService } from '../../app/core/locale/locale.service';
import { HeadTagService } from '../../app/core/metadata/head-tag.service';
import { CorrelationIdService } from '../../app/correlation-id/correlation-id.service';
import { InitService } from '../../app/init.service';
import { isNotEmpty } from '../../app/shared/empty.util';
import {
isEmpty,
isNotEmpty,
} from '../../app/shared/empty.util';
import { MenuService } from '../../app/shared/menu/menu.service';
import { ThemeService } from '../../app/shared/theme-support/theme.service';
import { Angulartics2DSpace } from '../../app/statistics/angulartics/dspace-provider';
@@ -30,6 +33,7 @@ import {
APP_CONFIG_STATE,
AppConfig,
} from '../../config/app-config.interface';
import { BuildConfig } from '../../config/build-config.interface';
import { environment } from '../../environments/environment';
/**
@@ -41,7 +45,7 @@ export class ServerInitService extends InitService {
protected store: Store<AppState>,
protected correlationIdService: CorrelationIdService,
protected transferState: TransferState,
@Inject(APP_CONFIG) protected appConfig: AppConfig,
@Inject(APP_CONFIG) protected appConfig: BuildConfig,
protected translate: TranslateService,
protected localeService: LocaleService,
protected angulartics2DSpace: Angulartics2DSpace,
@@ -68,9 +72,7 @@ export class ServerInitService extends InitService {
return async () => {
this.checkAuthenticationToken();
this.saveAppConfigForCSR();
if (this.appConfig.ui.transferState) {
this.saveAppState();
}
this.saveAppState();
this.initCorrelationId();
this.checkEnvironment();
@@ -92,14 +94,16 @@ export class ServerInitService extends InitService {
* @private
*/
private saveAppState() {
this.transferState.onSerialize(InitService.NGRX_STATE, () => {
let state;
this.store.pipe(take(1)).subscribe((saveState: any) => {
state = saveState;
});
if (this.appConfig.ssr.transferState && (isEmpty(this.appConfig.rest.ssrBaseUrl) || this.appConfig.ssr.replaceRestUrl)) {
this.transferState.onSerialize(InitService.NGRX_STATE, () => {
let state;
this.store.pipe(take(1)).subscribe((saveState: any) => {
state = saveState;
});
return state;
});
return state;
});
}
}
private saveAppConfigForCSR(): void {