diff --git a/src/app/shared/state/common/common.effects.ts b/src/app/shared/state/common/common.effects.ts index 4974b4f..cd94243 100644 --- a/src/app/shared/state/common/common.effects.ts +++ b/src/app/shared/state/common/common.effects.ts @@ -1,6 +1,6 @@ import { createEffect, ofType } from '@ngrx/effects'; import { from, of } from 'rxjs'; -import { catchError, delay, exhaustMap, map, mergeMap } from 'rxjs/operators'; +import { catchError, concatMap, delay, exhaustMap, map, mergeMap } from 'rxjs/operators'; export abstract class CommonEffect { constructor(protected actions$: any, protected actions: any, protected service: any) {} @@ -8,7 +8,7 @@ export abstract class CommonEffect { loadAll$ = createEffect(() => { return this.actions$.pipe( ofType(this.actions.loadAll), - delay(1500), + delay(0), map((action: any) => action.payload), exhaustMap((requestFilter) => from(this.service.getAll(requestFilter)).pipe( @@ -22,9 +22,9 @@ export abstract class CommonEffect { loadMore$ = createEffect(() => { return this.actions$.pipe( ofType(this.actions.loadMore), - delay(1500), + delay(0), map((action: any) => action.payload), - exhaustMap((requestFilter) => + concatMap((requestFilter) => from(this.service.getAll(requestFilter)).pipe( map((page: any) => this.actions.loadMoreSuccess({ payload: page })), catchError((err) => of(this.actions.loadMoreFail({ error: err }))), @@ -36,7 +36,7 @@ export abstract class CommonEffect { loadOne$ = createEffect(() => { return this.actions$.pipe( ofType(this.actions.loadOne), - delay(1500), + delay(0), mergeMap((action: any) => from(this.service.getOne(action.id)).pipe( map((item: any) => this.actions.loadOneSuccess({ payload: item })), @@ -49,7 +49,7 @@ export abstract class CommonEffect { createOne$ = createEffect(() => { return this.actions$.pipe( ofType(this.actions.create), - delay(1500), + delay(0), mergeMap((action: any) => from(this.service.create(action.payload)).pipe( map((created) => this.actions.createSuccess({ payload: created })), @@ -62,7 +62,7 @@ export abstract class CommonEffect { updateOne$ = createEffect(() => { return this.actions$.pipe( ofType(this.actions.update), - delay(1500), + delay(0), mergeMap((action: any) => from(this.service.update(action.payload)).pipe( map((updated) => @@ -79,7 +79,7 @@ export abstract class CommonEffect { deleteOne$ = createEffect(() => { return this.actions$.pipe( ofType(this.actions.delete), - delay(1500), + delay(0), mergeMap((action: any) => from(this.service.delete(action.id)).pipe( map(() => this.actions.deleteSuccess({ id: action.id })), @@ -92,7 +92,7 @@ export abstract class CommonEffect { count$ = createEffect(() => { return this.actions$.pipe( ofType(this.actions.count), - delay(1500), + delay(0), mergeMap(() => from(this.service.count()).pipe( map((count: any) => this.actions.countSuccess({ payload: count })), diff --git a/src/app/shared/state/common/common.reducer.ts b/src/app/shared/state/common/common.reducer.ts index a51487a..408617e 100644 --- a/src/app/shared/state/common/common.reducer.ts +++ b/src/app/shared/state/common/common.reducer.ts @@ -101,8 +101,6 @@ export class CommonReducer> { }, })), on(this.actions.loadMoreSuccess, (state, { payload }) => { - const selected = state.entities.find((i: any) => i.id === state.selectedId); - return { ...state, loading: false, @@ -113,7 +111,7 @@ export class CommonReducer> { }, }; }), - on(this.actions.loadAllFail, (state, error) => ({ + on(this.actions.loadMoreFail, (state, error) => ({ ...state, loading: false, action: { diff --git a/src/app/website/pages/certificates/certificates.component.html b/src/app/website/pages/certificates/certificates.component.html index cdd0d21..b026fa5 100644 --- a/src/app/website/pages/certificates/certificates.component.html +++ b/src/app/website/pages/certificates/certificates.component.html @@ -1,91 +1,79 @@ - - - -
- -
-
-
-

{{ getTranslation(language.acronym, certificateGroup.nameTranslations) }}

-
- - -
-
-
-
-

{{ getTranslation(language.acronym, certificate.nameTranslations) }}

-
{{ certificate.date | date }}
-

{{ getTranslation(language.acronym, certificate.descriptionTranslations) }}

-
- -
+ + +
+
+
+
+

{{ getTranslation(language.acronym, certificateGroup.nameTranslations) }}

+
+ + +
+
+
+
+

{{ getTranslation(language.acronym, certificate.nameTranslations) }}

+
{{ certificate.date | date }}
+

{{ getTranslation(language.acronym, certificate.descriptionTranslations) }}

+ +
+
-
-
- - - - - - -
-
+
+
+ + + + + +
- - -
-
- - -
-
-
-

{{ 'general.loading' | translate }}

-
- - - - - -
- -
-
-
-

{{ 'general.loading' | translate }}

+
- - - - - -
+ + +
-
+ + +
+
+
+

{{ 'general.loading' | translate }}

+
+ + + + + +
+
+
+ + + +
diff --git a/src/app/website/pages/certificates/certificates.component.ts b/src/app/website/pages/certificates/certificates.component.ts index 8c99c26..522d33a 100644 --- a/src/app/website/pages/certificates/certificates.component.ts +++ b/src/app/website/pages/certificates/certificates.component.ts @@ -11,16 +11,14 @@ import { inject, } from '@angular/core'; import { Store } from '@ngrx/store'; -import { BehaviorSubject, Observable, pairwise, startWith, take, zip } from 'rxjs'; +import { BehaviorSubject, Observable, filter, map, pairwise, startWith, zip } from 'rxjs'; import { CertificateGroup } from 'src/app/backoffice/tables/certificate-group/models/certificate-group.model'; import { certificateGroupActions } from 'src/app/backoffice/tables/certificate-group/state/certificate-group.actions'; import { certificateGroupReducer } from 'src/app/backoffice/tables/certificate-group/state/certificate-group.reducer'; -import { CertificateType } from 'src/app/backoffice/tables/certificate-type/models/certificate-type.model'; -import { certificateTypeReducer } from 'src/app/backoffice/tables/certificate-type/state/certificate-type.reducer'; import { Certificate } from 'src/app/backoffice/tables/certificate/models/certificate.model'; -import { certificateReducer } from 'src/app/backoffice/tables/certificate/state/certificate.reducer'; import { Language } from 'src/app/backoffice/tables/language/models/language.model'; import { TranslationProvider } from 'src/app/shared/models/translation-provider.model'; +import { ActionStatus, ActionType } from 'src/app/shared/state/common/common-state'; import { publicLanguageReducer } from 'src/app/shared/state/languages/public-language.reducer'; import Swiper, { A11y, Autoplay, Navigation, Pagination, Scrollbar, SwiperOptions } from 'swiper'; @@ -45,14 +43,11 @@ export class CertificatesComponent extends TranslationProvider implements OnInit language$: Observable = this.store.select(publicLanguageReducer.getOne); - certificates$: Observable = this.store.select(certificateReducer.getAll); - loadingCertificates$: Observable = this.store.select(certificateReducer.getLoading); - certificateTypes$: Observable = this.store.select(certificateTypeReducer.getAll); - loadingCertificateTypes$: Observable = this.store.select(certificateTypeReducer.getLoading); - certificateGroups$: Observable = this.store.select(certificateGroupReducer.getAll); - loadingMoreCertificateGroups$: Observable = this.store.select(certificateGroupReducer.getLoading); - loadingCertificateGroups$: Observable = this.store.select(certificateGroupReducer.getLoading).pipe(take(2)); + skillTypesActionStatus$: Observable = this.store.select(certificateGroupReducer.getAction).pipe( + filter((action) => !!action && action.type === ActionType.LOAD_MANY), + map((action) => action.status), + ); certificateGroupCount$: BehaviorSubject = new BehaviorSubject(0); tabIndexes: { groupId: any; value: number }[] = []; @@ -178,4 +173,8 @@ export class CertificatesComponent extends TranslationProvider implements OnInit getCertificateGroupEnterAnimationState(certificateGroupId: string): 'inViewport' | 'notInViewport' { return this.certificateElementStates.get(certificateGroupId) || 'notInViewport'; } + + get ActionStatus() { + return ActionStatus; + } } diff --git a/src/app/website/pages/certificates/certificates.module.ts b/src/app/website/pages/certificates/certificates.module.ts index 00b8265..34cecbe 100644 --- a/src/app/website/pages/certificates/certificates.module.ts +++ b/src/app/website/pages/certificates/certificates.module.ts @@ -2,6 +2,7 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { TranslateModule } from '@ngx-translate/core'; import { SkeletonModule } from 'primeng/skeleton'; +import { GenericErrorModule } from 'src/app/shared/components/generic-error/generic-error.module'; import { DirectivesModule } from 'src/app/shared/modules/directives.module'; import { PipesModule } from 'src/app/shared/modules/pipes.module'; import { SwiperModule } from 'swiper/angular'; @@ -18,6 +19,7 @@ import { CertificatesComponent } from './certificates.component'; SwiperModule, DirectivesModule, TranslateModule, + GenericErrorModule, ], }) export class CertificatesModule {}