Skip to content
Snippets Groups Projects
Commit ac1a982e authored by Florent Poittevin's avatar Florent Poittevin
Browse files

NGXS decomposition in 3 actions

parent e662c02c
No related branches found
No related tags found
1 merge request!3Develop
import {AipModel, DipModel} from '@app/generated-api';
import {CollectionTypedModel} from '@app/model/collection-typed.model';
export class GetAllDip {
static readonly type = '[Access] Get All Dip';
......@@ -15,7 +18,14 @@ export class SearchDip {
export class SearchDipSuccess {
static readonly type = '[Access] Search Dip Success';
constructor(public search: string) {
constructor(public aips: CollectionTypedModel<DipModel>) {
}
}
export class SearchDipFail {
static readonly type = '[Access] Search Dip Fail';
constructor() {
}
}
import {GetAllDip, SearchDip} from '@app/access/access.action';
import {GetAllDip, SearchDip, SearchDipFail, SearchDipSuccess} from '@app/access/access.action';
import {AppStateModel} from '@app/app.state';
import {DipModel} from '@app/generated-api';
import {CollectionTypedModel} from '@app/model/collection-typed.model';
......@@ -52,7 +52,7 @@ export class AccessState {
}
@Action(SearchDip, {cancelUncompleted: true})
viewDip(ctx: StateContext<AccessStateModel>, action: SearchDip) {
searchDip(ctx: StateContext<AccessStateModel>, action: SearchDip) {
ctx.patchState({
isLoading: true,
});
......@@ -61,24 +61,31 @@ export class AccessState {
'info.name': action.search,
};
console.log('test', 'test');
return this.dlcmService.accessDipGetFilter(null, null, null, filters)
.pipe(
tap((collectionDips: CollectionTypedModel<DipModel>) => {
ctx.patchState({
dips: collectionDips._data,
totalDip: collectionDips._page.totalItems,
isLoading: false,
});
ctx.dispatch(new SearchDipSuccess(collectionDips));
}),
catchError(e => {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(new SearchDipFail());
throw e;
}),
);
}
@Action(SearchDipSuccess)
searchDipSuccess(ctx: StateContext<AccessStateModel>, action: SearchDipSuccess) {
ctx.patchState({
dips: action.aips._data,
totalDip: action.aips._page.totalItems,
isLoading: false,
});
}
@Action(SearchDipFail)
searchDipFail(ctx: StateContext<AccessStateModel>) {
ctx.patchState({
isLoading: false,
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment