| 35 | }; |
| 36 | |
| 37 | export const issueReducer = (state = initialState, action = {}) => { |
| 38 | switch (action.type) { |
| 39 | case POST_ISSUE_COMMENT.PENDING: |
| 40 | return { |
| 41 | ...state, |
| 42 | isPostingComment: true, |
| 43 | }; |
| 44 | case POST_ISSUE_COMMENT.SUCCESS: |
| 45 | return { |
| 46 | ...state, |
| 47 | comments: [...state.comments, action.payload], |
| 48 | isPostingComment: false, |
| 49 | }; |
| 50 | case POST_ISSUE_COMMENT.ERROR: |
| 51 | return { |
| 52 | ...state, |
| 53 | error: action.payload, |
| 54 | isPostingComment: false, |
| 55 | }; |
| 56 | case DELETE_ISSUE_COMMENT.PENDING: |
| 57 | return { |
| 58 | ...state, |
| 59 | isDeletingComment: true, |
| 60 | }; |
| 61 | case DELETE_ISSUE_COMMENT.SUCCESS: |
| 62 | return { |
| 63 | ...state, |
| 64 | comments: state.comments.filter( |
| 65 | comment => comment.id !== action.payload |
| 66 | ), |
| 67 | isDeletingComment: false, |
| 68 | }; |
| 69 | case DELETE_ISSUE_COMMENT.ERROR: |
| 70 | return { |
| 71 | ...state, |
| 72 | error: action.payload, |
| 73 | isDeletingComment: false, |
| 74 | }; |
| 75 | case EDIT_ISSUE_COMMENT.PENDING: |
| 76 | return { |
| 77 | ...state, |
| 78 | isEditingComment: true, |
| 79 | }; |
| 80 | case EDIT_ISSUE_COMMENT.SUCCESS: |
| 81 | return { |
| 82 | ...state, |
| 83 | comments: state.comments.map( |
| 84 | comment => |
| 85 | comment.id === action.payload.id |
| 86 | ? { |
| 87 | ...comment, |
| 88 | body: action.payload.body, |
| 89 | body_html: action.payload.body_html, |
| 90 | } |
| 91 | : comment |
| 92 | ), |
| 93 | isEditingComment: false, |
| 94 | }; |