@@ -3,6 +3,10 @@ import {
33 Injectable ,
44 Optional ,
55} from '@angular/core' ;
6+ import {
7+ select ,
8+ Store ,
9+ } from '@ngrx/store' ;
610import cloneDeep from 'lodash/cloneDeep' ;
711import {
812 combineLatest ,
@@ -11,6 +15,7 @@ import {
1115 switchMap ,
1216} from 'rxjs' ;
1317import {
18+ filter ,
1419 map ,
1520 take ,
1621} from 'rxjs/operators' ;
@@ -20,7 +25,10 @@ import {
2025 AppConfig ,
2126} from '../../config/app-config.interface' ;
2227import { environment } from '../../environments/environment' ;
28+ import { AppState } from '../app.reducer' ;
29+ import { RetrieveAuthenticatedEpersonSuccessAction } from '../core/auth/auth.actions' ;
2330import { AuthService } from '../core/auth/auth.service' ;
31+ import { getAuthenticatedUser } from '../core/auth/selectors' ;
2432import { EPersonDataService } from '../core/eperson/eperson-data.service' ;
2533import { EPerson } from '../core/eperson/models/eperson.model' ;
2634import { CookieService } from '../core/services/cookie.service' ;
@@ -91,6 +99,7 @@ export class AccessibilitySettingsService {
9199 protected ePersonService : EPersonDataService ,
92100 @Optional ( ) protected orejimeService : OrejimeService ,
93101 @Inject ( APP_CONFIG ) protected appConfig : AppConfig ,
102+ private store : Store < AppState > ,
94103 ) {
95104 }
96105
@@ -234,7 +243,19 @@ export class AccessibilitySettingsService {
234243 switchMap ( operations =>
235244 isNotEmpty ( operations ) ? this . ePersonService . patch ( user , operations ) : createSuccessfulRemoteDataObject$ ( { } ) ) ,
236245 getFirstCompletedRemoteData ( ) ,
237- switchMap ( rd => rd . hasSucceeded ? ofMetadata ( ) : ofFailed ( ) ) ,
246+ switchMap ( rd => {
247+ if ( rd . hasSucceeded ) {
248+ this . store . dispatch ( new RetrieveAuthenticatedEpersonSuccessAction ( user ) ) ;
249+ return this . store . pipe (
250+ select ( getAuthenticatedUser ) ,
251+ filter ( ( u ) => ! ! u && u . id === user . id && u . firstMetadataValue ( ACCESSIBILITY_SETTINGS_METADATA_KEY ) === user . firstMetadataValue ( ACCESSIBILITY_SETTINGS_METADATA_KEY ) ) ,
252+ take ( 1 ) ,
253+ switchMap ( ( ) => ofMetadata ( ) ) ,
254+ ) ;
255+ } else {
256+ return ofFailed ( ) ;
257+ }
258+ } ) ,
238259 ) ;
239260 }
240261
0 commit comments