Changeset 68d02ca for src/Clients/Angular
- Timestamp:
- 11/04/21 22:09:29 (3 years ago)
- Branches:
- dev
- Children:
- dd264cb
- Parents:
- 91bfcf4
- Location:
- src/Clients/Angular/finki-chattery/src
- Files:
-
- 5 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Clients/Angular/finki-chattery/src/app/core/state/question-facade.service.ts
r91bfcf4 r68d02ca 19 19 GetQuestionState, 20 20 GetSearchQuestions, 21 RespondToAnswer, 21 22 SetCorrectAnswer, 22 23 VoteAnswer … … 85 86 } 86 87 88 public respondToAnswer(answerUid: string, questionUid: string, text: string): void { 89 this.dispatchEffect(new RespondToAnswer(questionUid, answerUid, text)); 90 } 91 87 92 public fetchQuestion(questionUid: string): void { 88 93 this.dispatchEffect(new GetQuestionState(questionUid)); -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question-state-request.models.ts
r91bfcf4 r68d02ca 4 4 constructor(public voteType: VoteType) {} 5 5 } 6 7 export class RespondToAnswerRequest { 8 constructor(public text: string) {} 9 } -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.actions.ts
r91bfcf4 r68d02ca 3 3 4 4 import { 5 AnswerResponseQuestionStateViewModel, 5 6 PreviewQuestionViewModel, 6 7 QuestionStateViewModel, … … 13 14 GetQuestionState = '[Question] Get state', 14 15 GetQuestionStateSuccess = '[Question] Get state success', 16 RespondToAnswer = '[Question] RespondToAnswer', 17 RespondToAnswerSuccess = '[Question] RespondToAnswer success', 15 18 SetCorrectAnswer = '[Question] Set Correct Answer', 16 19 SetCorrectAnswerSuccess = '[Question] Set Correct Answer success', … … 100 103 } 101 104 105 export class RespondToAnswer implements Action { 106 readonly type = QuestionActionTypes.RespondToAnswer; 107 108 constructor(public questionUid: string, public answerUid: string, public text: string) {} 109 } 110 111 export class RespondToAnswerSuccess implements Action { 112 readonly type = QuestionActionTypes.RespondToAnswerSuccess; 113 114 constructor(public payload: AnswerResponseQuestionStateViewModel, public answerUid: string) {} 115 } 116 102 117 export class EffectStartedWorking implements Action { 103 118 readonly type = QuestionActionTypes.EffectStartedWorking; … … 125 140 | VoteAnswerSuccess 126 141 | SetCorrectAnswerSuccess 142 | RespondToAnswerSuccess 127 143 | EffectStartedWorking 128 144 | EffectFinishedWorking -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.effects.ts
r91bfcf4 r68d02ca 8 8 import { NotificationService } from '../../services/notification.service'; 9 9 import { QuestionFacadeService } from '../question-facade.service'; 10 import { VoteAnswerRequest } from './question-state-request.models'; 11 import { PreviewQuestionResponse, QuestionStateResponse, VoteAnswerResponse } from './question-state-response.models'; 10 import { RespondToAnswerRequest, VoteAnswerRequest } from './question-state-request.models'; 11 import { 12 AnswerResponseQuestionStateResponse, 13 PreviewQuestionResponse, 14 QuestionStateResponse, 15 VoteAnswerResponse 16 } from './question-state-response.models'; 12 17 import { 13 18 EffectFinishedWorking, … … 22 27 GetSearchQuestionsSuccess, 23 28 QuestionActionTypes, 29 RespondToAnswer, 30 RespondToAnswerSuccess, 24 31 SetCorrectAnswer, 25 32 SetCorrectAnswerSuccess, … … 137 144 ); 138 145 }); 146 147 respondToAnswer$ = createEffect(() => { 148 return this.actions$.pipe( 149 ofType<RespondToAnswer>(QuestionActionTypes.RespondToAnswer), 150 mergeMap((action) => { 151 return this.api 152 .post<AnswerResponseQuestionStateResponse>( 153 `v1/questions/${action.questionUid}/answers/${action.answerUid}/answerresponses`, 154 new RespondToAnswerRequest(action.text) 155 ) 156 .pipe( 157 tap((state) => this.notification.successNotification('success-answer-response')), 158 switchMap((state) => [ 159 new RespondToAnswerSuccess(QuestionMapper.ToAnswerResponseQuestionStateViewModel(state), action.answerUid), 160 new EffectFinishedWorking() 161 ]), 162 catchError((err) => [new EffectFinishedWorkingError(err)]) 163 ); 164 }) 165 ); 166 }); 139 167 } -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.mapper.ts
r91bfcf4 r68d02ca 14 14 } from 'src/app/shared-app/models'; 15 15 import { TranslateFromJsonService } from 'src/app/shared-app/services'; 16 import { PreviewQuestionResponse, QuestionStateResponse, VoteAnswerResponse } from './question-state-response.models'; 16 import { 17 AnswerResponseQuestionStateResponse, 18 PreviewQuestionResponse, 19 QuestionStateResponse, 20 VoteAnswerResponse 21 } from './question-state-response.models'; 17 22 18 23 export class QuestionMapper { … … 118 123 return new VoteAnswerViewModel(response.answerUid, response.voteUid, response.voteType); 119 124 } 125 126 public static ToAnswerResponseQuestionStateViewModel( 127 response: AnswerResponseQuestionStateResponse 128 ): AnswerResponseQuestionStateViewModel { 129 const answerResponseStudent = new AnswerResponseStudentQuestionStateViewModel( 130 response.studentResponse.uid, 131 response.studentResponse.index, 132 response.studentResponse.imageUrl, 133 response.studentResponse.reputation 134 ); 135 136 return new AnswerResponseQuestionStateViewModel(response.uid, response.text, moment(response.createdOn), answerResponseStudent); 137 } 120 138 } -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.reducers.ts
r91bfcf4 r68d02ca 90 90 }; 91 91 } 92 case QuestionActionTypes.RespondToAnswerSuccess: { 93 if (state.question) { 94 return { 95 ...state, 96 question: { 97 ...state.question, 98 answers: state.question.answers.map((x) => { 99 if (x.uid === action.answerUid) { 100 return { 101 ...x, 102 answerResponses: [...x.answerResponses, action.payload] 103 }; 104 } 105 106 return x; 107 }) 108 } 109 }; 110 } 111 112 return { 113 ...state 114 }; 115 } 92 116 case QuestionActionTypes.EffectStartedWorking: { 93 117 return { -
src/Clients/Angular/finki-chattery/src/app/shared-app/components/components.ts
r91bfcf4 r68d02ca 9 9 import { PreviewQuestionFullComponent } from './question/preview-question-full/preview-question-full.component'; 10 10 import { QuestionPreviewComponent } from './question/question-preview/question-preview.component'; 11 import { RespondToAnswerDialogComponent } from './question/respond-to-answer-dialog/respond-to-answer-dialog.component'; 11 12 import { SearchQuestionComponent } from './question/search-question/search-question.component'; 12 13 import { StudentCardComponent } from './question/student-card/student-card.component'; … … 24 25 AskQuestionSharedComponent, 25 26 PreviewQuestionFullComponent, 26 TextEditorComponent 27 TextEditorComponent, 28 RespondToAnswerDialogComponent 27 29 ]; -
src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/question-preview/question-preview.component.html
r91bfcf4 r68d02ca 45 45 <div *ngFor="let answerResponse of answer.answerResponses"> 46 46 {{ answerResponse.text }} 47 <mat-chip class="cursor" selected>{{ answerResponse.student.index }}</mat-chip> -47 <mat-chip class="cursor">{{ answerResponse.student.index }}</mat-chip> - 48 48 {{ answerResponse.createdOn | momentDate: 'LL' }} 49 49 <hr /> … … 52 52 </div> 53 53 </mat-card-content> 54 <mat-card-actions> </mat-card-actions> 54 <mat-card-actions> 55 <app-button (action)="openRespondToAnswerDialog(answer.uid)" [buttonType]="ButtonType.Basic">{{ 56 'question-preview-respond-to-answer-button' | translate 57 }}</app-button> 58 </mat-card-actions> 55 59 </mat-card> 56 60 </ng-container> -
src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/question-preview/question-preview.component.ts
r91bfcf4 r68d02ca 5 5 6 6 import { QuestionStateViewModel, VoteType } from 'src/app/shared-app/models'; 7 import { SharedDialogService } from 'src/app/shared-app/services/shared-dialog.service'; 7 8 import { ButtonType } from '../../generic/button/button.models'; 8 9 … … 17 18 working = true; 18 19 ButtonType = ButtonType; 19 constructor(private questionFacade: QuestionFacadeService, private notification: NotificationService) {} 20 constructor( 21 private questionFacade: QuestionFacadeService, 22 private notification: NotificationService, 23 private dialog: SharedDialogService 24 ) {} 20 25 21 26 ngOnInit(): void { … … 39 44 this.questionFacade.setCorrectAnswer(questionUid, answerUid); 40 45 } 46 47 openRespondToAnswerDialog(answerUid: string): void { 48 this.dialog.respondToAnswer(this.question.uid, answerUid); 49 } 41 50 } -
src/Clients/Angular/finki-chattery/src/assets/translations/en.json
r91bfcf4 r68d02ca 55 55 "sucess-vote": "Successfully voted answer", 56 56 "success-correct-answer": "Successfully set correct answer", 57 "success-answer-response": "Successfully responded to answer", 57 58 "ask-question-ask-button": "Ask question", 59 "question-preview-respond-to-answer-button": "Respond to answer", 60 "respond-to-answer-title": "Respond to answer", 61 "respond-to-answer-title-text-placeholder": "Response text", 62 "close-button": "Close", 63 "submit-button": "Submit", 58 64 "AnswerAlreadyUpvoted": "You have already upvoted this answer", 59 65 "AnswerAlreadyDownvoted": "You have already downvoted this answer",
Note:
See TracChangeset
for help on using the changeset viewer.