mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-06 02:26:49 +00:00
13 sharing recipes (#49)
* fix: update description image * feat: share using navigator api
This commit is contained in:
parent
3a66b00c74
commit
b7aca38912
2 changed files with 24 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Chef's Meal Planner
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
|
|
|||
|
|
@ -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