diff --git a/components/recipe/view.vue b/components/recipe/view.vue index 56c9d4c..4630118 100644 --- a/components/recipe/view.vue +++ b/components/recipe/view.vue @@ -2,6 +2,25 @@ import type { Recipe } from "~/types/recipe"; defineProps<{ recipe: Recipe }>(); + +const shareRecipe = async (recipe: Recipe) => { + const url = + useRequestURL().href.split("/").slice(0, -1).join("/") + "/" + recipe.id; + + if (navigator.share) { + try { + await navigator.share({ + title: recipe.title, + text: `Check out this recipe: ${recipe.title}`, + url, + }); + } catch (error) { + alert("Failed to share the recipe."); + } + } else { + alert("Sharing not supported on this device."); + } +};