Newer
Older
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
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType, concatLatestFrom } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { of } from 'rxjs';
import { map, tap, mergeMap, catchError } from 'rxjs/operators';
import { ToastrService } from 'ngx-toastr';
import * as svomJsonKwActions from '../actions/svom-json-kw.actions';
import * as svomJsonKwSelector from '../selectors/svom-json-kw.selector';
import { SvomJsonKwService } from '../services/svom-json-kw.service';
/**
* @class
* @classdesc Svom Json Kw effects.
*/
@Injectable()
export class SvomJsonKwEffects {
selectAcronym$ = createEffect((): any =>
this.actions$.pipe(
ofType(svomJsonKwActions.selectAcronym),
map(() => svomJsonKwActions.loadKwSearchable())
)
);
loadKwSearchable$ = createEffect(() =>
this.actions$.pipe(
ofType(svomJsonKwActions.loadKwSearchable),
concatLatestFrom(() => this.store.select(svomJsonKwSelector.selectAcronymSelected)),
mergeMap(([action, acronymSelected]) => this.svomJsonKwService.loadKwSearchable(acronymSelected)
.pipe(
map(svomKeywords => svomJsonKwActions.loadKwSearchableSuccess({ svomKeywords })),
catchError(() => of(svomJsonKwActions.loadKwSearchableFail()))
)
)
)
);
loadKwSearchableSuccess$ = createEffect(() =>
this.actions$.pipe(
ofType(svomJsonKwActions.loadKwSearchableSuccess),
tap(() => {
this.toastr.success('SVOM Json Keywords was loaded successfully and are now available to product criteria', 'SVOM Json Keywords loaded')
})
), { dispatch: false}
);
addDatabaseFail$ = createEffect(() =>
this.actions$.pipe(
ofType(svomJsonKwActions.loadKwSearchableFail),
tap(() => this.toastr.error('Failure to load Keywords', 'SVOM Json Keywords loaded failed'))
), { dispatch: false}
);
constructor(
private actions$: Actions,
private store: Store<{ }>,
private svomJsonKwService: SvomJsonKwService,
private toastr: ToastrService
) {}
}