| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  |   <div> | 
					
						
							|  |  |  |     <client-only> | 
					
						
							|  |  |  |       <RecipePage v-if="recipe" :recipe="recipe" /> | 
					
						
							|  |  |  |     </client-only> | 
					
						
							|  |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  | import { defineComponent, ref, useAsync, useMeta, useRoute, useRouter } from "@nuxtjs/composition-api"; | 
					
						
							|  |  |  | import RecipePage from "~/components/Domain/Recipe/RecipePage/RecipePage.vue"; | 
					
						
							|  |  |  | import { usePublicApi } from "~/composables/api/api-client"; | 
					
						
							|  |  |  | import { useRecipeMeta } from "~/composables/recipes"; | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  |   components: { RecipePage }, | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |   layout: "basic", | 
					
						
							|  |  |  |   setup() { | 
					
						
							|  |  |  |     const route = useRoute(); | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  |     const router = useRouter(); | 
					
						
							|  |  |  |     const recipeId = route.value.params.id; | 
					
						
							|  |  |  |     const api = usePublicApi(); | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-06 17:14:14 -09:00
										 |  |  |     const { meta, title } = useMeta(); | 
					
						
							| 
									
										
										
										
											2022-09-10 19:29:21 +02:00
										 |  |  |     const { recipeMeta } = useRecipeMeta(); | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const recipe = useAsync(async () => { | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  |       const { data, error } = await api.shared.getShared(recipeId); | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  |       if (error) { | 
					
						
							|  |  |  |         console.error("error loading recipe -> ", error); | 
					
						
							|  |  |  |         router.push("/"); | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  |       if (data) { | 
					
						
							|  |  |  |         title.value = data?.name || ""; | 
					
						
							| 
									
										
										
										
											2022-09-10 19:29:21 +02:00
										 |  |  |         const metaObj = recipeMeta(ref(data)); | 
					
						
							|  |  |  |         meta.value = metaObj.meta; | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 20:08:33 -08:00
										 |  |  |       return data; | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       recipe, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   head: {}, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | </script> |