mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-06 02:26:49 +00:00
feat: share using navigator api
This commit is contained in:
parent
c22169def7
commit
34c1076523
1 changed files with 23 additions and 0 deletions
|
|
@ -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.");
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -29,6 +48,10 @@ defineProps<{ recipe: Recipe }>();
|
|||
<p class="prose prose-lg max-w-none w-full">
|
||||
{{ recipe.instructions }}
|
||||
</p>
|
||||
<button class="btn btn-accent mt-4" @click="shareRecipe(recipe)">
|
||||
<icon name="uil:share-alt" class="mr-2 w-6 h-6" />
|
||||
Share Recipe
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Reference in a new issue