Add Web Share api to ContextMenu.vue. Copy to clipboard is the fallback

This commit is contained in:
Matthias Borremans 2021-06-03 14:48:20 +02:00
commit c120598097
4 changed files with 15305 additions and 18 deletions

15287
frontend/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -33,6 +33,7 @@
<script> <script>
import ConfirmationDialog from "@/components/UI/Dialogs/ConfirmationDialog.vue"; import ConfirmationDialog from "@/components/UI/Dialogs/ConfirmationDialog.vue";
import { api } from "@/api"; import { api } from "@/api";
import { utils } from "@/utils";
export default { export default {
components: { components: {
ConfirmationDialog, ConfirmationDialog,
@ -44,6 +45,9 @@ export default {
menuIcon: { menuIcon: {
default: "mdi-dots-vertical", default: "mdi-dots-vertical",
}, },
name: {
type: String,
},
}, },
computed: { computed: {
loggedIn() { loggedIn() {
@ -64,8 +68,8 @@ export default {
action: "print", action: "print",
}, },
{ {
title: this.$t("general.link"), title: this.$t("Share"),
icon: "mdi-content-copy", icon: "mdi-share-variant",
color: "accent", color: "accent",
action: "share", action: "share",
}, },
@ -88,6 +92,9 @@ export default {
...this.defaultMenu, ...this.defaultMenu,
]; ];
}, },
recipeText() {
return this.$t(`I wanted to share you my {0} recipe.`, [this.name]);
},
}, },
data() { data() {
return { return {
@ -103,7 +110,15 @@ export default {
this.$refs.deleteRecipieConfirm.open(); this.$refs.deleteRecipieConfirm.open();
break; break;
case "share": case "share":
this.updateClipboard(); if (navigator.share){
navigator.share({
title: this.name,
text: this.recipeText,
url: this.recipeURL,
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('WebShareAPI not supported', error))
} else this.updateClipboard();
break; break;
case "edit": case "edit":
this.$router.push(`/recipe/${this.slug}` + "?edit=true"); this.$router.push(`/recipe/${this.slug}` + "?edit=true");
@ -123,10 +138,11 @@ export default {
updateClipboard() { updateClipboard() {
const copyText = this.recipeURL; const copyText = this.recipeURL;
navigator.clipboard.writeText(copyText).then( navigator.clipboard.writeText(copyText).then(
() => console.log("Copied", copyText), () => console.log("Copied to Clipboard", copyText),
() => console.log("Copied Failed", copyText) () => console.log("Copied Failed", copyText),
utils.notify.success("Copied to Clipboard")
); );
}, },
}, },
}; }
</script> </script>

View file

@ -34,7 +34,11 @@
:value="rating" :value="rating"
></v-rating> ></v-rating>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<ContextMenu :slug="slug" menu-icon="mdi-dots-horizontal" /> <ContextMenu
:slug="slug"
menu-icon="mdi-dots-horizontal"
:name="name"
/>
</div> </div>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>

View file

@ -27,7 +27,7 @@
<Rating :value="rating" :name="name" :slug="slug" :small="true" /> <Rating :value="rating" :name="name" :slug="slug" :small="true" />
<v-spacer></v-spacer> <v-spacer></v-spacer>
<RecipeChips :truncate="true" :items="tags" :title="false" :limit="2" :small="true" :isCategory="false" /> <RecipeChips :truncate="true" :items="tags" :title="false" :limit="2" :small="true" :isCategory="false" />
<ContextMenu :slug="slug" /> <ContextMenu :slug="slug" :name="name"/>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-hover> </v-hover>