@@ -32,6 +32,12 @@ import {
3232 isNotEmpty ,
3333} from '../shared/empty.util' ;
3434import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils' ;
35+ import { Store } from '@ngrx/store' ;
36+ import { RetrieveAuthenticatedEpersonSuccessAction } from '../core/auth/auth.actions' ;
37+ import { AppState } from '../app.reducer' ;
38+ import { select } from '@ngrx/store' ;
39+ import { filter } from 'rxjs/operators' ;
40+ import { getAuthenticatedUser } from '../core/auth/selectors' ;
3541
3642/**
3743 * Name of the cookie used to store the settings locally
@@ -91,6 +97,7 @@ export class AccessibilitySettingsService {
9197 protected ePersonService : EPersonDataService ,
9298 @Optional ( ) protected orejimeService : OrejimeService ,
9399 @Inject ( APP_CONFIG ) protected appConfig : AppConfig ,
100+ private store : Store < AppState > ,
94101 ) {
95102 }
96103
@@ -234,7 +241,19 @@ export class AccessibilitySettingsService {
234241 switchMap ( operations =>
235242 isNotEmpty ( operations ) ? this . ePersonService . patch ( user , operations ) : createSuccessfulRemoteDataObject$ ( { } ) ) ,
236243 getFirstCompletedRemoteData ( ) ,
237- switchMap ( rd => rd . hasSucceeded ? ofMetadata ( ) : ofFailed ( ) ) ,
244+ switchMap ( rd => {
245+ if ( rd . hasSucceeded ) {
246+ this . store . dispatch ( new RetrieveAuthenticatedEpersonSuccessAction ( user ) ) ;
247+ return this . store . pipe (
248+ select ( getAuthenticatedUser ) ,
249+ filter ( ( u ) => ! ! u && u . id === user . id && u . firstMetadataValue ( ACCESSIBILITY_SETTINGS_METADATA_KEY ) === user . firstMetadataValue ( ACCESSIBILITY_SETTINGS_METADATA_KEY ) ) ,
250+ take ( 1 ) ,
251+ switchMap ( ( ) => ofMetadata ( ) ) ,
252+ ) ;
253+ } else {
254+ return ofFailed ( ) ;
255+ }
256+ } ) ,
238257 ) ;
239258 }
240259
0 commit comments