mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
119602: Fix SSR error by making klaroService optional
KlaroService handles cookies which are not applicable during SSR. By making the service optional, and handling the case when it is not available, SSR can do its work without throwing NullInjectorErrors.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Component, OnDestroy, OnInit, Optional } from '@angular/core';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
import {
|
||||
AccessibilitySetting,
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { BehaviorSubject, distinctUntilChanged, map, Subscription, take } from 'rxjs';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { isEmpty } from 'src/app/shared/empty.util';
|
||||
import { hasValue, isEmpty } from 'src/app/shared/empty.util';
|
||||
import { AlertType } from '../../shared/alert/alert-type';
|
||||
import { KlaroService } from '../../shared/cookies/klaro.service';
|
||||
|
||||
@@ -35,7 +35,7 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy {
|
||||
protected settingsService: AccessibilitySettingsService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected translateService: TranslateService,
|
||||
protected klaroService: KlaroService,
|
||||
@Optional() protected klaroService: KlaroService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -45,11 +45,19 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy {
|
||||
this.subscriptions.push(
|
||||
this.authService.isAuthenticated().pipe(distinctUntilChanged())
|
||||
.subscribe(val => this.isAuthenticated.next(val)),
|
||||
this.klaroService.getSavedPreferences().pipe(
|
||||
map(preferences => preferences?.accessibility === true),
|
||||
distinctUntilChanged(),
|
||||
).subscribe(val => this.cookieIsAccepted.next(val)),
|
||||
);
|
||||
|
||||
if (hasValue(this.klaroService)) {
|
||||
this.subscriptions.push(
|
||||
this.klaroService.getSavedPreferences().pipe(
|
||||
map(preferences => preferences?.accessibility === true),
|
||||
distinctUntilChanged(),
|
||||
).subscribe(val => this.cookieIsAccepted.next(val))
|
||||
);
|
||||
} else {
|
||||
this.cookieIsAccepted.next(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
Reference in New Issue
Block a user