Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.reducers.ts

    ra3b5f34 r2a9d9d1  
     1import { AnswerQuestionStateViewModel, VoteType } from 'src/app/shared-app/models';
    12import { QuestionAction, QuestionActionTypes } from './question.actions';
    23import { initialState, QuestionState } from './question.state';
     
    2526        searchQuestionsQuery: action.query
    2627      };
     28    case QuestionActionTypes.VoteAnswerSuccess: {
     29      if (state.question) {
     30        return {
     31          ...state,
     32          question: {
     33            ...state.question,
     34            answers: state.question.answers.map((x) => {
     35              if (x.uid === action.payload.answerUid) {
     36                let votesCountNew = x.votesCount;
     37
     38                switch (action.payload.voteType) {
     39                  case VoteType.Upvote:
     40                    votesCountNew++;
     41                    break;
     42                  case VoteType.Downvote:
     43                    votesCountNew--;
     44                    break;
     45                }
     46
     47                return {
     48                  ...x,
     49                  votesCount: votesCountNew
     50                };
     51              }
     52
     53              return x;
     54            })
     55          }
     56        };
     57      }
     58
     59      return {
     60        ...state
     61      };
     62    }
     63    case QuestionActionTypes.SetCorrectAnswerSuccess: {
     64      if (state.question) {
     65        return {
     66          ...state,
     67          question: {
     68            ...state.question,
     69            answers: state.question.answers.map((x) => {
     70              if (x.correctAnswer) {
     71                return {
     72                  ...x,
     73                  correctAnswer: false
     74                };
     75              }
     76              if (x.uid === action.payload) {
     77                return {
     78                  ...x,
     79                  correctAnswer: true
     80                };
     81              }
     82              return x;
     83            })
     84          }
     85        };
     86      }
     87
     88      return {
     89        ...state
     90      };
     91    }
    2792    case QuestionActionTypes.EffectStartedWorking: {
    2893      return {
Note: See TracChangeset for help on using the changeset viewer.