| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  |   <v-container class="mx-0 my-3 pa"> | 
					
						
							|  |  |  |     <v-row> | 
					
						
							|  |  |  |       <v-col | 
					
						
							|  |  |  |         v-for="(day, index) in plan" | 
					
						
							|  |  |  |         :key="index" | 
					
						
							|  |  |  |         cols="12" | 
					
						
							|  |  |  |         sm="12" | 
					
						
							|  |  |  |         md="4" | 
					
						
							|  |  |  |         lg="4" | 
					
						
							|  |  |  |         xl="2" | 
					
						
							|  |  |  |         class="col-borders my-1 d-flex flex-column" | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <v-card class="mb-2 border-left-primary rounded-sm px-2"> | 
					
						
							|  |  |  |           <v-container class="px-0"> | 
					
						
							|  |  |  |             <v-row no-gutters style="width: 100%;"> | 
					
						
							|  |  |  |               <v-col cols="10"> | 
					
						
							|  |  |  |                 <p class="pl-2 my-1"> | 
					
						
							|  |  |  |                   {{ $d(day.date, "short") }} | 
					
						
							|  |  |  |                 </p> | 
					
						
							|  |  |  |               </v-col> | 
					
						
							|  |  |  |               <v-col class="d-flex justify-top" cols="2"> | 
					
						
							|  |  |  |                 <GroupMealPlanDayContextMenu v-if="day.recipes.length" :recipes="day.recipes" /> | 
					
						
							|  |  |  |               </v-col> | 
					
						
							|  |  |  |             </v-row> | 
					
						
							|  |  |  |           </v-container> | 
					
						
							|  |  |  |         </v-card> | 
					
						
							|  |  |  |         <div v-for="section in day.sections" :key="section.title"> | 
					
						
							|  |  |  |           <div class="py-2 d-flex flex-column"> | 
					
						
							|  |  |  |             <div class="primary" style="width: 50px; height: 2.5px"></div> | 
					
						
							|  |  |  |             <p class="text-overline my-0"> | 
					
						
							|  |  |  |               {{ section.title }} | 
					
						
							|  |  |  |             </p> | 
					
						
							|  |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  |           <RecipeCardMobile | 
					
						
							|  |  |  |             v-for="mealplan in section.meals" | 
					
						
							|  |  |  |             :key="mealplan.id" | 
					
						
							|  |  |  |             :recipe-id="mealplan.recipe ? mealplan.recipe.id : ''" | 
					
						
							|  |  |  |             class="mb-2" | 
					
						
							| 
									
										
										
										
											2024-02-16 03:57:02 +11:00
										 |  |  |             :rating="mealplan.recipe ? mealplan.recipe.rating : 0" | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  |             :slug="mealplan.recipe ? mealplan.recipe.slug : mealplan.title" | 
					
						
							|  |  |  |             :description="mealplan.recipe ? mealplan.recipe.description : mealplan.text" | 
					
						
							|  |  |  |             :name="mealplan.recipe ? mealplan.recipe.name : mealplan.title" | 
					
						
							| 
									
										
										
										
											2024-07-10 10:43:33 +01:00
										 |  |  |             :tags="mealplan.recipe ? mealplan.recipe.tags : []" | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  |           /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </v-col> | 
					
						
							|  |  |  |     </v-row> | 
					
						
							|  |  |  |   </v-container> | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  | import { computed, defineComponent, useContext } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  | import { MealsByDate } from "./types"; | 
					
						
							|  |  |  | import { ReadPlanEntry } from "~/lib/api/types/meal-plan"; | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  | import GroupMealPlanDayContextMenu from "~/components/Domain/Household/GroupMealPlanDayContextMenu.vue"; | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  | import RecipeCardMobile from "~/components/Domain/Recipe/RecipeCardMobile.vue"; | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  | import { RecipeSummary } from "~/lib/api/types/recipe"; | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   components: { | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  |     GroupMealPlanDayContextMenu, | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  |     RecipeCardMobile, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   props: { | 
					
						
							|  |  |  |     mealplans: { | 
					
						
							|  |  |  |       type: Array as () => MealsByDate[], | 
					
						
							|  |  |  |       required: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   setup(props) { | 
					
						
							|  |  |  |     type DaySection = { | 
					
						
							|  |  |  |       title: string; | 
					
						
							|  |  |  |       meals: ReadPlanEntry[]; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     type Days = { | 
					
						
							|  |  |  |       date: Date; | 
					
						
							|  |  |  |       sections: DaySection[]; | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  |       recipes: RecipeSummary[]; | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |   const { i18n } = useContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  |     const plan = computed<Days[]>(() => { | 
					
						
							|  |  |  |       return props.mealplans.reduce((acc, day) => { | 
					
						
							|  |  |  |         const out: Days = { | 
					
						
							|  |  |  |           date: day.date, | 
					
						
							|  |  |  |           sections: [ | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |             { title: i18n.tc("meal-plan.breakfast"), meals: [] }, | 
					
						
							|  |  |  |             { title: i18n.tc("meal-plan.lunch"), meals: [] }, | 
					
						
							|  |  |  |             { title: i18n.tc("meal-plan.dinner"), meals: [] }, | 
					
						
							|  |  |  |             { title: i18n.tc("meal-plan.side"), meals: [] }, | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  |           ], | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  |           recipes: [], | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const meal of day.meals) { | 
					
						
							|  |  |  |           if (meal.entryType === "breakfast") { | 
					
						
							|  |  |  |             out.sections[0].meals.push(meal); | 
					
						
							|  |  |  |           } else if (meal.entryType === "lunch") { | 
					
						
							|  |  |  |             out.sections[1].meals.push(meal); | 
					
						
							|  |  |  |           } else if (meal.entryType === "dinner") { | 
					
						
							|  |  |  |             out.sections[2].meals.push(meal); | 
					
						
							|  |  |  |           } else if (meal.entryType === "side") { | 
					
						
							|  |  |  |             out.sections[3].meals.push(meal); | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2023-11-21 12:11:10 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |           if (meal.recipe) { | 
					
						
							|  |  |  |             out.recipes.push(meal.recipe); | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2023-03-02 09:45:06 -09:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Drop empty sections
 | 
					
						
							|  |  |  |         out.sections = out.sections.filter((section) => section.meals.length > 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         acc.push(out); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return acc; | 
					
						
							|  |  |  |       }, [] as Days[]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       plan, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> |