| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  |   <div> | 
					
						
							|  |  |  |     <!-- Edit Dialog --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-if="editTarget" | 
					
						
							|  |  |  |       v-model="dialogStates.edit" | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |       width="100%" | 
					
						
							|  |  |  |       max-width="1100px" | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  |       :icon="$globals.icons.pages" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       :title="$t('general.edit')" | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  |       :submit-icon="$globals.icons.save" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       :submit-text="$t('general.save')" | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |       :submit-disabled="!editTarget.queryFilterString" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       can-submit | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  |       @submit="editCookbook" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         <CookbookEditor | 
					
						
							|  |  |  |           v-model="editTarget" | 
					
						
							|  |  |  |           :actions="actions" | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     <v-container | 
					
						
							|  |  |  |       v-if="book" | 
					
						
							|  |  |  |       fluid | 
					
						
							|  |  |  |       class="py-0 my-0" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-sheet | 
					
						
							|  |  |  |         color="transparent" | 
					
						
							|  |  |  |         class="d-flex flex-column w-100 pa-0 ma-0" | 
					
						
							|  |  |  |         elevation="0" | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <div class="d-flex align-center w-100 mb-2"> | 
					
						
							|  |  |  |           <v-icon size="large" class="mr-3"> | 
					
						
							|  |  |  |             {{ $globals.icons.pages }} | 
					
						
							|  |  |  |           </v-icon> | 
					
						
							|  |  |  |           <v-toolbar-title class="headline mb-0"> | 
					
						
							|  |  |  |             {{ book.name }} | 
					
						
							|  |  |  |           </v-toolbar-title> | 
					
						
							|  |  |  |           <v-spacer /> | 
					
						
							|  |  |  |           <BaseButton | 
					
						
							|  |  |  |             v-if="canEdit" | 
					
						
							|  |  |  |             class="mx-1" | 
					
						
							|  |  |  |             :edit="true" | 
					
						
							|  |  |  |             @click="handleEditCookbook" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         <div v-if="book.description" class="subtitle-1 text-grey-lighten-1 mb-2"> | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  |           {{ book.description }} | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </v-sheet> | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       <v-container class="pa-0"> | 
					
						
							|  |  |  |         <RecipeCardSection | 
					
						
							|  |  |  |           class="mb-5 mx-1" | 
					
						
							|  |  |  |           :recipes="recipes" | 
					
						
							|  |  |  |           :query="{ cookbook: slug }" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           @sort-recipes="assignSorted" | 
					
						
							|  |  |  |           @replace-recipes="replaceRecipes" | 
					
						
							|  |  |  |           @append-recipes="appendRecipes" | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  |           @delete="removeRecipe" | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       </v-container> | 
					
						
							|  |  |  |     </v-container> | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | <script lang="ts"> | 
					
						
							|  |  |  | import { useLazyRecipes } from "~/composables/recipes"; | 
					
						
							|  |  |  | import RecipeCardSection from "@/components/Domain/Recipe/RecipeCardSection.vue"; | 
					
						
							|  |  |  | import { useCookbook, useCookbooks } from "~/composables/use-group-cookbooks"; | 
					
						
							|  |  |  | import { useLoggedInState } from "~/composables/use-logged-in-state"; | 
					
						
							|  |  |  | import type { RecipeCookBook } from "~/lib/api/types/cookbook"; | 
					
						
							|  |  |  | import CookbookEditor from "~/components/Domain/Cookbook/CookbookEditor.vue"; | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | export default defineNuxtComponent({ | 
					
						
							|  |  |  |   components: { RecipeCardSection, CookbookEditor }, | 
					
						
							|  |  |  |   setup() { | 
					
						
							|  |  |  |     const $auth = useMealieAuth(); | 
					
						
							|  |  |  |     const { isOwnGroup } = useLoggedInState(); | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const route = useRoute(); | 
					
						
							|  |  |  |     const groupSlug = computed(() => route.params.groupSlug as string || $auth.user.value?.groupSlug || ""); | 
					
						
							| 
									
										
										
										
											2023-11-05 19:07:02 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const { recipes, appendRecipes, assignSorted, removeRecipe, replaceRecipes } = useLazyRecipes(isOwnGroup.value ? null : groupSlug.value); | 
					
						
							|  |  |  |     const slug = route.params.slug as string; | 
					
						
							|  |  |  |     const { getOne } = useCookbook(isOwnGroup.value ? null : groupSlug.value); | 
					
						
							|  |  |  |     const { actions } = useCookbooks(); | 
					
						
							|  |  |  |     const router = useRouter(); | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const tab = ref(null); | 
					
						
							|  |  |  |     const book = getOne(slug); | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const isOwnHousehold = computed(() => { | 
					
						
							|  |  |  |       if (!($auth.user.value && book.value?.householdId)) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-11-05 13:57:30 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       return $auth.user.value.householdId === book.value.householdId; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     const canEdit = computed(() => isOwnGroup.value && isOwnHousehold.value); | 
					
						
							| 
									
										
										
										
											2024-11-05 13:57:30 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const dialogStates = reactive({ | 
					
						
							|  |  |  |       edit: false, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const editTarget = ref<RecipeCookBook | null>(null); | 
					
						
							|  |  |  |     function handleEditCookbook() { | 
					
						
							|  |  |  |       dialogStates.edit = true; | 
					
						
							|  |  |  |       editTarget.value = book.value; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     async function editCookbook() { | 
					
						
							|  |  |  |       if (!editTarget.value) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       const response = await actions.updateOne(editTarget.value); | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       if (response?.slug && book.value?.slug !== response?.slug) { | 
					
						
							|  |  |  |         // if name changed, redirect to new slug
 | 
					
						
							|  |  |  |         router.push(`/g/${route.params.groupSlug}/cookbooks/${response?.slug}`); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         // otherwise reload the page, since the recipe criteria changed
 | 
					
						
							|  |  |  |         router.go(0); | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       dialogStates.edit = false; | 
					
						
							|  |  |  |       editTarget.value = null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-03-26 14:02:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     useSeoMeta({ | 
					
						
							|  |  |  |       title: book?.value?.name || "Cookbook", | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-09-14 09:01:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     return { | 
					
						
							|  |  |  |       book, | 
					
						
							|  |  |  |       slug, | 
					
						
							|  |  |  |       tab, | 
					
						
							|  |  |  |       appendRecipes, | 
					
						
							|  |  |  |       assignSorted, | 
					
						
							|  |  |  |       recipes, | 
					
						
							|  |  |  |       removeRecipe, | 
					
						
							|  |  |  |       replaceRecipes, | 
					
						
							|  |  |  |       canEdit, | 
					
						
							|  |  |  |       dialogStates, | 
					
						
							|  |  |  |       editTarget, | 
					
						
							|  |  |  |       handleEditCookbook, | 
					
						
							|  |  |  |       editCookbook, | 
					
						
							|  |  |  |       actions, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> |