| Total Complexity | 1 |
| Complexity/F | 0 |
| Lines of Code | 39 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { Classification } from "../../models/types"; |
||
| 2 | import { |
||
| 3 | ClassificationAction, |
||
| 4 | GET_CLASSIFICATIONS_STARTED, |
||
| 5 | GET_CLASSIFICATIONS_SUCCEEDED, |
||
| 6 | GET_CLASSIFICATIONS_FAILED, |
||
| 7 | } from "./classificationActions"; |
||
| 8 | import { mapToObject, getId } from "../../helpers/queries"; |
||
| 9 | |||
| 10 | export interface ClassificationState { |
||
| 11 | byId: { |
||
| 12 | [id: number]: Classification; |
||
| 13 | }; |
||
| 14 | loading: boolean; |
||
| 15 | } |
||
| 16 | |||
| 17 | export const initClassificationState = (): ClassificationState => ({ |
||
| 18 | byId: [], |
||
| 19 | loading: false, |
||
| 20 | }); |
||
| 21 | |||
| 22 | const classificationReducer = ( |
||
| 23 | state = initClassificationState(), |
||
| 24 | action: ClassificationAction, |
||
| 25 | ): ClassificationState => { |
||
| 26 | switch (action.type) { |
||
| 27 | case GET_CLASSIFICATIONS_STARTED: |
||
| 28 | return { ...state, loading: true }; |
||
| 29 | case GET_CLASSIFICATIONS_SUCCEEDED: |
||
| 30 | return { byId: mapToObject(action.payload, getId), loading: false }; |
||
| 31 | case GET_CLASSIFICATIONS_FAILED: |
||
| 32 | return { ...state, loading: false }; |
||
| 33 | default: |
||
| 34 | return state; |
||
| 35 | } |
||
| 36 | }; |
||
| 37 | |||
| 38 | export default classificationReducer; |
||
| 39 |