Bladeren bron

Remove Moment parameters from AssignToDay reducer

Tatiana Inama 7 jaren geleden
bovenliggende
commit
38158bf6da

+ 2 - 3
recipes/src/containers/Planner/actions.ts

@@ -1,5 +1,4 @@
 import { DBRecipe } from 'types/recipes';
-import { Moment } from 'moment'
 import { Meal, RecipePlan, Weekday } from 'types/planner';
 
 export const ADD_TO_BACKLOG = 'ADD_TO_BACKLOG';
@@ -19,7 +18,7 @@ const actions = {
     type: REMOVE_FROM_BACKLOG,
     recipe,
   }),
-  assignToDay: (recipe: RecipePlan, day: Moment, meal: Meal) => ({
+  assignToDay: (recipe: RecipePlan, day: Weekday, meal: Meal) => ({
     type: ASSIGN_TO_DAY,
     recipe,
     day,
@@ -45,7 +44,7 @@ export type RemoveFromBacklog = {
 export type AssignToDay = {
   type: typeof ASSIGN_TO_DAY,
   recipe: RecipePlan,
-  day: Moment,
+  day: Weekday,
   meal: Meal
 }
 

+ 4 - 9
recipes/src/containers/Planner/index.tsx

@@ -3,24 +3,20 @@ import { RouteComponentProps } from 'react-router';
 import Navbar from 'components/Navbar';
 import { AppState } from 'store/configureStore';
 import { connect } from 'react-redux';
-import { PlannerState, Weekday, Meal, RecipePlan, DayPlan } from 'types/planner';
+import { PlannerState, Weekday, Meal, DayPlan } from 'types/planner';
 import { Grid, Row, Cell } from "@material/react-layout-grid";
 import Card from 'components/Card';
 import PlannerActions, { Actions } from './actions';
-import moment, { Moment } from 'moment';
+import moment from 'moment';
 import { DragDropContext, Droppable, Draggable, DropResult } from 'react-beautiful-dnd';
 import './styles.scss';
-import { mkWeekData, mkWeekDay, getWeekDay } from 'services/time';
-import { DBRecipe } from 'types/recipes';
+import { getWeekDay } from 'services/time';
 import Button from 'components/Button';
 
 
 interface PlannerContainerProps extends RouteComponentProps, PlannerState, Actions {
 }
 
-const [ DAY, DATE ] = [ 0, 1 ];
-
-type _WeekDay = [ Weekday, string ]
 interface PlannerContainerState {
   week: [Weekday, string][]
 }
@@ -52,8 +48,7 @@ class PlannerContainer extends Component<PlannerContainerProps, PlannerContainer
     const recipe = this.findRecipe(result.draggableId);
     if (result.destination && recipe) {
       const [idx, day, meal] = result.destination.droppableId.split('-');
-      const dayData = this.state.week[parseInt(idx)];
-      this.props.assignToDay(recipe, moment(dayData[DATE]), meal as Meal);
+      this.props.assignToDay(recipe, day as Weekday, meal as Meal);
       this.props.removeFromBacklog(recipe);
     }
   }

+ 5 - 6
recipes/src/containers/Planner/reducers.ts

@@ -1,6 +1,6 @@
-import { ActionTypes, ADD_TO_BACKLOG, ASSIGN_TO_DAY } from './actions';
-import { PlannerState, Weekday } from 'types/planner';
-import { getWeekNumber, mkWeekDay, getWeekDay } from 'services/time';
+import { ActionTypes } from './actions';
+import { PlannerState } from 'types/planner';
+import { getWeekNumber, mkWeekDay } from 'services/time';
 
 
 const initialState: PlannerState = {
@@ -44,13 +44,12 @@ const PlannerReducer = (
         backlog: state.backlog.concat([action.recipe])
       };
     case 'ASSIGN_TO_DAY':
-      let weekday = getWeekDay(action.day) as Weekday;
       return {
         ...state,
         planner: {
           ...state.planner,
-          [weekday]: {
-            ...state.planner[weekday],
+          [action.day]: {
+            ...state.planner[action.day],
             [action.meal]: action.recipe
           }
         }