Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 8x 8x 8x 8x 8x 8x 3x 8x 8x 1x 8x 8x 1x 8x 8x 2x 2x 2x | import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store, select } from '@ngrx/store';
import { from } from 'rxjs';
import { concatMap, filter, map, mergeMap, switchMap } from 'rxjs/operators';
import { CMSService } from 'ish-core/services/cms/cms.service';
import { selectRouteParam } from 'ish-core/store/core/router';
import { setBreadcrumbData } from 'ish-core/store/core/viewconf';
import { personalizationStatusDetermined } from 'ish-core/store/customer/user';
import { HttpStatusCodeService } from 'ish-core/utils/http-status-code/http-status-code.service';
import {
mapErrorToAction,
mapToPayloadProperty,
useCombinedObservableOnAction,
whenTruthy,
} from 'ish-core/utils/operators';
import {
loadContentPage,
loadContentPageFail,
loadContentPageSuccess,
setBreadcrumbForContentPage,
} from './pages.actions';
import { getBreadcrumbForContentPage } from './pages.selectors';
@Injectable()
export class PagesEffects {
constructor(
private actions$: Actions,
private store: Store,
private cmsService: CMSService,
private httpStatusCodeService: HttpStatusCodeService
) {}
loadContentPage$ = createEffect(() =>
this.actions$.pipe(
useCombinedObservableOnAction(this.actions$.pipe(ofType(loadContentPage)), personalizationStatusDetermined),
mapToPayloadProperty('contentPageId'),
mergeMap(contentPageId =>
this.cmsService
.getContentPage(contentPageId)
.pipe(map(loadContentPageSuccess), mapErrorToAction(loadContentPageFail))
)
)
);
redirectIfErrorInContentPage$ = createEffect(
() =>
this.actions$.pipe(
ofType(loadContentPageFail),
concatMap(() => from(this.httpStatusCodeService.setStatus(404)))
),
{ dispatch: false }
);
selectedContentPage$ = createEffect(() =>
this.store.pipe(
select(selectRouteParam('contentPageId')),
whenTruthy(),
map(contentPageId => loadContentPage({ contentPageId }))
)
);
setBreadcrumbForContentPage$ = createEffect(() =>
this.actions$.pipe(
ofType(setBreadcrumbForContentPage),
mapToPayloadProperty('rootId'),
// eslint-disable-next-line rxjs/no-unsafe-switchmap
switchMap(rootId =>
this.store.pipe(
select(getBreadcrumbForContentPage(rootId)),
filter(breadcrumbData => !!breadcrumbData),
map(breadcrumbData => setBreadcrumbData({ breadcrumbData }))
)
)
)
);
}
|