| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |   <div v-if="value && value.length > 0"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     <div | 
					
						
							|  |  |  |       v-if="!isCookMode" | 
					
						
							|  |  |  |       class="d-flex justify-start" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <h2 class="mt-1 text-h5 font-weight-medium opacity-80"> | 
					
						
							|  |  |  |         {{ $t("recipe.ingredients") }} | 
					
						
							|  |  |  |       </h2> | 
					
						
							|  |  |  |       <AppButtonCopy | 
					
						
							|  |  |  |         btn-class="ml-auto" | 
					
						
							|  |  |  |         :copy-text="ingredientCopyText" | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |     <div> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       <div | 
					
						
							|  |  |  |         v-for="(ingredient, index) in value" | 
					
						
							|  |  |  |         :key="'ingredient' + index" | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2024-11-11 12:21:44 +01:00
										 |  |  |         <template v-if="!isCookMode"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <h3 | 
					
						
							|  |  |  |             v-if="showTitleEditor[index]" | 
					
						
							|  |  |  |             class="mt-2" | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             {{ ingredient.title }} | 
					
						
							|  |  |  |           </h3> | 
					
						
							|  |  |  |           <v-divider v-if="showTitleEditor[index]" /> | 
					
						
							| 
									
										
										
										
											2024-11-11 12:21:44 +01:00
										 |  |  |         </template> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         <v-list-item | 
					
						
							|  |  |  |           density="compact" | 
					
						
							| 
									
										
										
										
											2025-06-28 15:59:58 +02:00
										 |  |  |           class="pa-0" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           @click.stop="toggleChecked(index)" | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <template #prepend> | 
					
						
							|  |  |  |             <v-checkbox | 
					
						
							|  |  |  |               v-model="checked[index]" | 
					
						
							|  |  |  |               hide-details | 
					
						
							|  |  |  |               class="pt-0 my-auto py-auto" | 
					
						
							|  |  |  |               color="secondary" | 
					
						
							|  |  |  |               density="comfortable" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </template> | 
					
						
							|  |  |  |           <v-list-item-title> | 
					
						
							|  |  |  |             <RecipeIngredientListItem | 
					
						
							|  |  |  |               :ingredient="ingredient" | 
					
						
							|  |  |  |               :disable-amount="disableAmount" | 
					
						
							|  |  |  |               :scale="scale" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </v-list-item-title> | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |         </v-list-item> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-08-21 17:32:09 +02:00
										 |  |  | import RecipeIngredientListItem from "./RecipeIngredientListItem.vue"; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { parseIngredientText } from "~/composables/recipes"; | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | import type { RecipeIngredient } from "~/lib/api/types/recipe"; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | export default defineNuxtComponent({ | 
					
						
							| 
									
										
										
										
											2023-08-21 17:32:09 +02:00
										 |  |  |   components: { RecipeIngredientListItem }, | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |   props: { | 
					
						
							|  |  |  |     value: { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       type: Array as () => RecipeIngredient[], | 
					
						
							| 
									
										
										
										
											2021-08-07 16:49:55 -08:00
										 |  |  |       default: () => [], | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |     disableAmount: { | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |       type: Boolean, | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |       default: false, | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |     scale: { | 
					
						
							|  |  |  |       type: Number, | 
					
						
							|  |  |  |       default: 1, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2024-11-11 12:21:44 +01:00
										 |  |  |     isCookMode: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |   }, | 
					
						
							|  |  |  |   setup(props) { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     function validateTitle(title?: string) { | 
					
						
							| 
									
										
										
										
											2022-02-13 12:23:42 -09:00
										 |  |  |       return !(title === undefined || title === "" || title === null); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const state = reactive({ | 
					
						
							|  |  |  |       checked: props.value.map(() => false), | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       showTitleEditor: computed(() => props.value.map(x => validateTitle(x.title))), | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     const ingredientCopyText = computed(() => { | 
					
						
							| 
									
										
										
										
											2024-01-22 14:21:04 -06:00
										 |  |  |       const components: string[] = []; | 
					
						
							|  |  |  |       props.value.forEach((ingredient) => { | 
					
						
							|  |  |  |         if (ingredient.title) { | 
					
						
							|  |  |  |           if (components.length) { | 
					
						
							|  |  |  |             components.push(""); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           components.push(`[${ingredient.title}]`); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         components.push(parseIngredientText(ingredient, props.disableAmount, props.scale, false)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return components.join("\n"); | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     function toggleChecked(index: number) { | 
					
						
							|  |  |  |       // TODO Find a better way to do this - $set is not available, and
 | 
					
						
							|  |  |  |       // direct array modifications are not propagated for some reason
 | 
					
						
							|  |  |  |       state.checked.splice(index, 1, !state.checked[index]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       ...toRefs(state), | 
					
						
							|  |  |  |       ingredientCopyText, | 
					
						
							|  |  |  |       toggleChecked, | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  | .dense-markdown p { | 
					
						
							|  |  |  |   margin: auto !important; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | </style> |