Changeset 48f727d for src/Clients
- Timestamp:
- 11/09/21 14:45:09 (3 years ago)
- Branches:
- dev
- Children:
- 74ad056
- Parents:
- 7e7cc4c
- Location:
- src/Clients/Angular/finki-chattery/src
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Clients/Angular/finki-chattery/src/app/core/state/question-facade.service.ts
r7e7cc4c r48f727d 14 14 import { AuthService } from '../services'; 15 15 import { 16 AnswerQuestion, 16 17 EffectStartedWorking, 17 18 GetPreviewQuestionsLatest, … … 99 100 } 100 101 102 public answerQuestion(questionUid: string, text: string): void { 103 this.dispatchEffect(new AnswerQuestion(questionUid, text)); 104 } 105 101 106 private fetchPreviewQuestionsLatest(): void { 102 107 this.dispatchEffect(new GetPreviewQuestionsLatest()); -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question-state-request.models.ts
r7e7cc4c r48f727d 8 8 constructor(public text: string) {} 9 9 } 10 11 export class AnswerQuestionRequest { 12 constructor(public text: string) {} 13 } -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.actions.ts
r7e7cc4c r48f727d 3 3 4 4 import { 5 AnswerQuestionStateViewModel, 5 6 AnswerResponseQuestionStateViewModel, 6 7 PreviewQuestionViewModel, … … 26 27 VoteAnswer = '[Question] Vote answer', 27 28 VoteAnswerSuccess = '[Question] Vote answer Success', 29 AnswerQuestion = '[Question] AnswerQuestion', 30 AnswerQuestionSuccess = '[Question] AnswerQuestion Success', 28 31 EffectStartedWorking = '[Question] Effect Started Working', 29 32 EffectFinishedWorking = '[Question] Effect Finished Working', 30 33 EffectFinishedWorkingError = '[Question] Effect Finished Working error' 34 } 35 36 export class AnswerQuestion implements Action { 37 readonly type = QuestionActionTypes.AnswerQuestion; 38 39 constructor(public questionUid: string, public text: string) {} 40 } 41 42 export class AnswerQuestionSuccess implements Action { 43 readonly type = QuestionActionTypes.AnswerQuestionSuccess; 44 45 constructor(public payload: AnswerQuestionStateViewModel) {} 31 46 } 32 47 … … 141 156 | SetCorrectAnswerSuccess 142 157 | RespondToAnswerSuccess 158 | AnswerQuestionSuccess 143 159 | EffectStartedWorking 144 160 | EffectFinishedWorking -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.effects.ts
r7e7cc4c r48f727d 8 8 import { NotificationService } from '../../services/notification.service'; 9 9 import { QuestionFacadeService } from '../question-facade.service'; 10 import { RespondToAnswerRequest, VoteAnswerRequest } from './question-state-request.models';10 import { AnswerQuestionRequest, RespondToAnswerRequest, VoteAnswerRequest } from './question-state-request.models'; 11 11 import { 12 AnswerQuestionStateResponse, 12 13 AnswerResponseQuestionStateResponse, 13 14 PreviewQuestionResponse, … … 16 17 } from './question-state-response.models'; 17 18 import { 19 AnswerQuestion, 20 AnswerQuestionSuccess, 18 21 EffectFinishedWorking, 19 22 EffectFinishedWorkingError, … … 165 168 ); 166 169 }); 170 171 answerQuestion$ = createEffect(() => { 172 return this.actions$.pipe( 173 ofType<AnswerQuestion>(QuestionActionTypes.AnswerQuestion), 174 mergeMap((action) => { 175 return this.api 176 .post<AnswerQuestionStateResponse>(`v1/questions/${action.questionUid}/answers`, new AnswerQuestionRequest(action.text)) 177 .pipe( 178 tap((state) => this.notification.successNotification('success-answer')), 179 switchMap((state) => [ 180 new AnswerQuestionSuccess(QuestionMapper.ToAnswerQuestionStateViewModel(state)), 181 new EffectFinishedWorking() 182 ]), 183 catchError((err) => [new EffectFinishedWorkingError(err)]) 184 ); 185 }) 186 ); 187 }); 167 188 } -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.mapper.ts
r7e7cc4c r48f727d 15 15 import { TranslateFromJsonService } from 'src/app/shared-app/services'; 16 16 import { 17 AnswerQuestionStateResponse, 17 18 AnswerResponseQuestionStateResponse, 18 19 PreviewQuestionResponse, … … 29 30 30 31 if (questionStateResponse.answersResponse.length > 0) { 31 answers = questionStateResponse.answersResponse.map((x) => { 32 let answerResponses: AnswerResponseQuestionStateViewModel[] = []; 33 34 if (x.answerResponsesResponse.length > 0) { 35 answerResponses = x.answerResponsesResponse.map((y) => { 36 const answerResponseStudent = new AnswerResponseStudentQuestionStateViewModel( 37 y.studentResponse.uid, 38 y.studentResponse.index, 39 y.studentResponse.imageUrl, 40 y.studentResponse.reputation 41 ); 42 43 return new AnswerResponseQuestionStateViewModel(y.uid, y.text, moment(y.createdOn), answerResponseStudent); 44 }); 45 } 46 47 const answerStudent = new AnswerStudentQuestionStateViewModel( 48 x.studentResponse.uid, 49 x.studentResponse.index, 50 x.studentResponse.imageUrl, 51 x.studentResponse.reputation 52 ); 53 54 return new AnswerQuestionStateViewModel( 55 x.uid, 56 x.text, 57 x.correctAnswer, 58 moment(x.createdOn), 59 x.votesCount, 60 answerStudent, 61 answerResponses 62 ); 63 }); 32 answers = questionStateResponse.answersResponse.map((x) => QuestionMapper.ToAnswerQuestionStateViewModel(x)); 64 33 } 65 34 … … 136 105 return new AnswerResponseQuestionStateViewModel(response.uid, response.text, moment(response.createdOn), answerResponseStudent); 137 106 } 107 108 public static ToAnswerQuestionStateViewModel(response: AnswerQuestionStateResponse): AnswerQuestionStateViewModel { 109 let answerResponses: AnswerResponseQuestionStateViewModel[] = []; 110 111 if (response.answerResponsesResponse.length > 0) { 112 answerResponses = response.answerResponsesResponse.map((y) => { 113 const answerResponseStudent = new AnswerResponseStudentQuestionStateViewModel( 114 y.studentResponse.uid, 115 y.studentResponse.index, 116 y.studentResponse.imageUrl, 117 y.studentResponse.reputation 118 ); 119 120 return new AnswerResponseQuestionStateViewModel(y.uid, y.text, moment(y.createdOn), answerResponseStudent); 121 }); 122 } 123 124 const answerStudent = new AnswerStudentQuestionStateViewModel( 125 response.studentResponse.uid, 126 response.studentResponse.index, 127 response.studentResponse.imageUrl, 128 response.studentResponse.reputation 129 ); 130 131 return new AnswerQuestionStateViewModel( 132 response.uid, 133 response.text, 134 response.correctAnswer, 135 moment(response.createdOn), 136 response.votesCount, 137 answerStudent, 138 answerResponses 139 ); 140 } 138 141 } -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.reducers.ts
r7e7cc4c r48f727d 114 114 }; 115 115 } 116 case QuestionActionTypes.AnswerQuestionSuccess: { 117 if (state.question) { 118 return { 119 ...state, 120 question: { 121 ...state.question, 122 answers: [...state.question.answers, action.payload] 123 } 124 }; 125 } 126 127 return { 128 ...state 129 }; 130 } 116 131 case QuestionActionTypes.EffectStartedWorking: { 117 132 return { -
src/Clients/Angular/finki-chattery/src/app/shared-app/components/components.ts
r7e7cc4c r48f727d 5 5 import { TextEditorComponent } from './generic/text-editor/text-editor.component'; 6 6 import { VoteComponent } from './generic/vote/vote.component'; 7 import { AnswerQuestionComponent } from './question/answer-question/answer-question.component'; 7 8 import { AskQuestionSharedComponent } from './question/ask-question-shared/ask-question-shared.component'; 8 9 import { PreviewQuestionDisplayComponent } from './question/preview-question-display/preview-question-display.component'; … … 26 27 PreviewQuestionFullComponent, 27 28 TextEditorComponent, 28 RespondToAnswerDialogComponent 29 RespondToAnswerDialogComponent, 30 AnswerQuestionComponent 29 31 ]; -
src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/preview-question-full/preview-question-full.component.html
r7e7cc4c r48f727d 40 40 </mat-card-content> 41 41 <mat-card-actions> 42 <app-button (action)="scrollToBottom()" [buttonType]="ButtonType.CallToAction">{{ 43 'preview-question-full-answer' | translate 44 }}</app-button> 42 45 <app-button appShareLink [buttonType]="ButtonType.Basic">{{ 'share-link' | translate }}</app-button> 43 46 </mat-card-actions> -
src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/preview-question-full/preview-question-full.component.ts
r7e7cc4c r48f727d 14 14 15 15 ngOnInit(): void {} 16 17 scrollToBottom(): void { 18 window.scrollTo(0, document.body.scrollHeight); 19 } 16 20 } -
src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/question-preview/question-preview.component.html
r7e7cc4c r48f727d 59 59 </mat-card> 60 60 </ng-container> 61 <app-answer-question></app-answer-question> 61 62 </div> -
src/Clients/Angular/finki-chattery/src/assets/translations/en.json
r7e7cc4c r48f727d 63 63 "submit-button": "Submit", 64 64 "header-student-questions": "Your questions", 65 "success-answer": "Successfully answered question", 66 "preview-question-full-answer": "Answer question", 67 "answer-question-title": "Give your answer to the question", 68 "answer-question-button": "Answer", 69 "StudentDoesNotOwnQuestion": "You do not own this question", 65 70 "AnswerAlreadyUpvoted": "You have already upvoted this answer", 66 71 "AnswerAlreadyDownvoted": "You have already downvoted this answer",
Note:
See TracChangeset
for help on using the changeset viewer.