wijohnst / johnston_home_hub

A React / Bootstrap / React Query / Mirage Dashboard for common home tasks
2 stars 0 forks source link

ENHANCEMENT: Add new `MealPlanner` endpoints to `mealPlannerAPI` #50

Open wijohnst opened 1 year ago

wijohnst commented 1 year ago

Adds the HTTP layer to MealPlanner

Subtasks

Other Tasks

wijohnst commented 1 year ago

GET: meal_plan/


interface Meal {
  _id: string;
  date: Date;
  mealType: string;
  recipes: Recipe[];
}

type response extends DefaultResponse = {
  mealPlans: Meal[]
}
wijohnst commented 1 year ago

PATCH: meal_plean/meal

type UpdatedMealRequest = {
  updatedMeal : Meal;
}

type UpdatedMealResponse = DefaultResponse;
wijohnst commented 1 year ago

GET: meal_plan/locked_recipes

enum LockableDays = [0, 1, 2, 3, 4, 5, 6];

interface LockedRecipe {
  _id: string;
  recipeId: string;
  mealType: MealTypes;
  daysLocked: LockableDays[];
}

type GetLockedRecipesResponse extends DefaultResponse {
  lockedRecipes: LockedRecipe[],
}
wijohnst commented 1 year ago

POST: meal_plan/locked_recipes

interface LockedRecipesRequest {
  recipeId: string;
  mealType: MealTypes[];
  daysLocked: LockableDays[];
}

type LockedRecipesResponse = DefaultResponse;
wijohnst commented 1 year ago

DELETE: meal_plan/locked_recipes

interface LockedRecipesRequest {
  lockedRecipeIdToDelete: string;
}

type LockedRecipesResponse = DefaultResponse;
wijohnst commented 1 year ago

Targeting MealPlan

Whenever the PlusIcon or a recipe Link is clicked, the MealPlanDoc data should be stored in MealPlanner local state.

const [ targetMealPlanDoc, setTargetMealPlanDoc ] = React.useState<MealPlanDoc | nill>(null)

DOM Tree For Passed Props

- MealPlanner.tsx //  Top-level local state
| -- MealTable.tsx  

Target the handleAddClick event handler and pass a MealPlanDoc object to store in top-level state

wijohnst commented 1 year ago

Viewing a Scheduled Recipe via InlineRecipeCard Component

When a user clicks a scheduled recipe in the MealTable, that recipe should be visible from the target MealPlan.

Image Pictured, the designs for the updated MealTable showing an InlineRecipeCard

Lock Functionality

The isolated InlineRecipe card should have 2 default states:

wijohnst commented 1 year ago

Handle DayOfWeekButtonBar Spillover

Image Pictured, the DayOfWeekButtonBar overflowing its container

wijohnst commented 1 year ago

LockedRecipe UI

Having returned an array of LockedRecipe objects from the BE, we now need to update the MealTable UI to reflect those recipes that are locked vs. those that aren't.

Image Pictured, designs for a LockedRecipe

In addition to updating the UI, this change should also dynamically control the state of the InlineRecipeCard component, specifically its main controls.

wijohnst commented 1 year ago

GET: meal_plan/locked_recipes

enum LockableDays = [0, 1, 2, 3, 4, 5, 6];

interface LockedRecipe {
  _id: string;
  recipeId: string;
  mealType: MealTypes;
  daysLocked: LockableDays[];
}

type GetLockedRecipesResponse extends DefaultResponse {
  lockedRecipes: LockedRecipe[],
}

Implement the enum

wijohnst commented 1 year ago

Add LockedRecipes to targetMealPlan.recipes when calling MealTable from MealPlanner

Currently the MealTable component consumes a MealPlanDoc object as its targetMealPlan prop. Every MealPlanDoc object has a recipes array that includes the RecipeDoc objects that exist on the MealPlan. In its current state this does not include LockedRecipes, which are not returned as part of the response from GET: meal_plan/.

Updated MealPlanner.tsx to fetch the RecipeDoc objects for all known LockedRecipes (based on LockedRecipe.recipeId) and add those recipes to the appropriate MealPlanDoc.

wijohnst commented 1 year ago

Add GET: /recipe/recipes Endpoint

interface GetRecipesByIdsRequest {
  recipeIds: string[];
}

interface GetRecipesByIdsResponse extends DefaultResponse {
  recipes: Recipe[];
}