reducers.ts 806 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const initialState = {
  2. recipes: {
  3. isFetching: false,
  4. data: [],
  5. selectedRecipe: undefined,
  6. }
  7. };
  8. export const recipesReducer = (
  9. state = initialState,
  10. action: any
  11. ) => {
  12. switch (action.type) {
  13. case 'REQUEST_RECIPES':
  14. return {
  15. ...state,
  16. recipes: {
  17. ...state.recipes,
  18. isFetching: action.isFetching,
  19. }
  20. }
  21. case 'RECEIVE_RECIPES':
  22. return {
  23. ...state,
  24. recipes: {
  25. ...state.recipes,
  26. isFetching: action.isFetching,
  27. data: action.payload || state.recipes.data,
  28. }
  29. }
  30. case 'SELECT_RECIPE':
  31. return {
  32. ...state,
  33. recipes: {
  34. ...state.recipes,
  35. selectedRecipe: action.payload
  36. }
  37. }
  38. default:
  39. return state;
  40. }
  41. }