Source

store/reducers/choirs.js

  1. // File imports
  2. import * as actionTypes from "../actions/actionTypes";
  3. import { updateObject } from "../utility";
  4. /**
  5. * Redux choirs tab reducer
  6. * @module reduxChoirsTabReducer
  7. * @category Redux
  8. * @author Dan Levy <danlevy124@gmail.com>
  9. */
  10. /**
  11. * Initial choirs tab state
  12. * @property {string} selectedChoirId - The selected choir id
  13. * @property {string} selectedChoirName - The selected choir name
  14. */
  15. const initialState = {
  16. selectedChoirId: null,
  17. selectedChoirName: null,
  18. };
  19. /**
  20. * Updates Redux choirs state based on an action type and a payload
  21. * @function
  22. * @param {object} state - The current state
  23. * @param {object} action - Any needed data (including the action type)
  24. * @returns {object} The new state
  25. */
  26. const choirsReducer = (state = initialState, action) => {
  27. switch (action.type) {
  28. case actionTypes.CHOIRS_CHOIR_SELECTED:
  29. return updateObject(state, {
  30. selectedChoirId: action.id,
  31. selectedChoirName: action.name,
  32. });
  33. default:
  34. return state;
  35. }
  36. };
  37. export default choirsReducer;