Changeset 8b6791f for src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.effects.ts
- Timestamp:
- 10/22/21 21:47:17 (3 years ago)
- Branches:
- dev
- Children:
- 466d1ac, 5ad5988
- Parents:
- 81c2e6f (diff), 70e04f1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.effects.ts
r81c2e6f r8b6791f 1 1 import { Injectable } from '@angular/core'; 2 2 import { Actions, createEffect, ofType } from '@ngrx/effects'; 3 import { catchError, switchMap } from 'rxjs/operators'; 3 import { catchError, filter, switchMap, withLatestFrom } from 'rxjs/operators'; 4 import { PreviewQuestionsOrderEnum } from 'src/app/shared-app/models'; 5 import { TranslateFromJsonService } from 'src/app/shared-app/services'; 4 6 5 7 import { BaseApiService } from 'src/app/shared-app/services/base-api.service'; 6 import { QuestionStateResponse } from './question-state.models'; 8 import { QuestionFacadeService } from '../question-facade.service'; 9 import { PreviewQuestionResponse, QuestionStateResponse } from './question-state.models'; 7 10 import { 8 11 EffectFinishedWorking, 9 12 EffectFinishedWorkingError, 13 GetPreviewQuestionsLatestSuccess, 14 GetPreviewQuestionsPopularSuccess, 10 15 GetQuestionState, 11 16 GetQuestionStateSuccess, … … 18 23 }) 19 24 export class QuestionEffects { 20 constructor(private actions$: Actions, private api: BaseApiService) {} 25 constructor( 26 private actions$: Actions, 27 private api: BaseApiService, 28 private translate: TranslateFromJsonService, 29 private facade: QuestionFacadeService 30 ) {} 21 31 22 32 getQuestionState$ = createEffect(() => { … … 31 41 ); 32 42 }); 43 44 getPreviewQuestionsLatest$ = createEffect(() => { 45 return this.actions$.pipe( 46 ofType<GetQuestionState>(QuestionActionTypes.GetPreviewQuestionsLatest), 47 withLatestFrom(this.facade.getPreviewQuestionsLatest()), 48 filter(([action, questions]) => questions.length === 0), 49 switchMap((action) => { 50 return this.api.get<PreviewQuestionResponse[]>(`v1/questions/preview?order=${PreviewQuestionsOrderEnum.Latest}`).pipe( 51 switchMap((state) => [ 52 new GetPreviewQuestionsLatestSuccess(QuestionMapper.ToPreviwQuestionsViewModel(state, this.translate)), 53 new EffectFinishedWorking() 54 ]), 55 catchError((err) => [new EffectFinishedWorkingError(err)]) 56 ); 57 }) 58 ); 59 }); 60 61 getPreviewQuestionsPopular$ = createEffect(() => { 62 return this.actions$.pipe( 63 ofType<GetQuestionState>(QuestionActionTypes.GetPreviewQuestionsPopular), 64 withLatestFrom(this.facade.getPreviewQuestionsPopular()), 65 filter(([action, questions]) => questions.length === 0), 66 switchMap((action) => { 67 return this.api.get<PreviewQuestionResponse[]>(`v1/questions/preview?order=${PreviewQuestionsOrderEnum.Popular}`).pipe( 68 switchMap((state) => [ 69 new GetPreviewQuestionsPopularSuccess(QuestionMapper.ToPreviwQuestionsViewModel(state, this.translate)), 70 new EffectFinishedWorking() 71 ]), 72 catchError((err) => [new EffectFinishedWorkingError(err)]) 73 ); 74 }) 75 ); 76 }); 33 77 }
Note:
See TracChangeset
for help on using the changeset viewer.