2021-05-02 04:46:02 +00:00
|
|
|
<template>
|
|
|
|
<div class="text-center">
|
|
|
|
<ConfirmationDialog
|
|
|
|
:title="$t('recipe.delete-recipe')"
|
|
|
|
:message="$t('recipe.delete-confirmation')"
|
|
|
|
color="error"
|
|
|
|
icon="mdi-alert-circle"
|
|
|
|
ref="deleteRecipieConfirm"
|
|
|
|
v-on:confirm="deleteRecipe()"
|
|
|
|
/>
|
|
|
|
<v-menu offset-y top left>
|
|
|
|
<template v-slot:activator="{ on, attrs }">
|
|
|
|
<v-btn color="primary" icon dark v-bind="attrs" v-on="on" @click.prevent>
|
|
|
|
<v-icon>{{ menuIcon }}</v-icon>
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
<v-list dense>
|
|
|
|
<v-list-item
|
|
|
|
v-for="(item, index) in loggedIn ? userMenu : defaultMenu"
|
|
|
|
:key="index"
|
|
|
|
@click="menuAction(item.action)"
|
|
|
|
>
|
|
|
|
<v-list-item-icon>
|
|
|
|
<v-icon v-text="item.icon" :color="item.color"></v-icon>
|
|
|
|
</v-list-item-icon>
|
|
|
|
<v-list-item-title>{{ item.title }}</v-list-item-title>
|
|
|
|
</v-list-item>
|
|
|
|
</v-list>
|
|
|
|
</v-menu>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import ConfirmationDialog from "@/components/UI/Dialogs/ConfirmationDialog.vue";
|
|
|
|
import { api } from "@/api";
|
2021-06-07 18:54:34 +00:00
|
|
|
import { utils } from "@/utils";
|
2021-05-02 04:46:02 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
ConfirmationDialog,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
menuIcon: {
|
|
|
|
default: "mdi-dots-vertical",
|
|
|
|
},
|
2021-06-07 18:54:34 +00:00
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
},
|
2021-05-02 04:46:02 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
loggedIn() {
|
|
|
|
return this.$store.getters.getIsLoggedIn;
|
|
|
|
},
|
|
|
|
baseURL() {
|
|
|
|
return window.location.origin;
|
|
|
|
},
|
|
|
|
recipeURL() {
|
|
|
|
return `${this.baseURL}/recipe/${this.slug}`;
|
|
|
|
},
|
|
|
|
defaultMenu() {
|
|
|
|
return [
|
|
|
|
{
|
2021-05-15 05:10:03 +00:00
|
|
|
title: this.$t("general.print"),
|
|
|
|
icon: "mdi-printer",
|
2021-05-02 04:46:02 +00:00
|
|
|
color: "accent",
|
2021-05-15 05:10:03 +00:00
|
|
|
action: "print",
|
2021-05-02 04:46:02 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-07 18:54:34 +00:00
|
|
|
title: this.$t("general.share"),
|
|
|
|
icon: "mdi-share-variant",
|
2021-05-02 04:46:02 +00:00
|
|
|
color: "accent",
|
|
|
|
action: "share",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
userMenu() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: this.$t("general.delete"),
|
2021-05-23 20:38:55 +00:00
|
|
|
icon: this.$globals.icons.delete,
|
2021-05-02 04:46:02 +00:00
|
|
|
color: "error",
|
|
|
|
action: "delete",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: this.$t("general.edit"),
|
2021-05-23 20:38:55 +00:00
|
|
|
icon: this.$globals.icons.edit,
|
2021-05-02 04:46:02 +00:00
|
|
|
color: "accent",
|
|
|
|
action: "edit",
|
|
|
|
},
|
|
|
|
...this.defaultMenu,
|
|
|
|
];
|
|
|
|
},
|
2021-06-07 18:54:34 +00:00
|
|
|
recipeText() {
|
|
|
|
return this.$t("recipe.share-recipe-message", [this.name]);
|
|
|
|
},
|
2021-05-02 04:46:02 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async menuAction(action) {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case "delete":
|
|
|
|
this.$refs.deleteRecipieConfirm.open();
|
|
|
|
break;
|
|
|
|
case "share":
|
2021-06-07 23:04:30 +00:00
|
|
|
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);
|
|
|
|
this.updateClipboard();
|
|
|
|
});
|
|
|
|
} else this.updateClipboard();
|
2021-05-02 04:46:02 +00:00
|
|
|
break;
|
|
|
|
case "edit":
|
|
|
|
this.$router.push(`/recipe/${this.slug}` + "?edit=true");
|
|
|
|
break;
|
2021-05-15 05:10:03 +00:00
|
|
|
case "print":
|
|
|
|
this.$router.push(`/recipe/${this.slug}` + "?print=true");
|
2021-05-02 04:46:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
async deleteRecipe() {
|
|
|
|
await api.recipes.delete(this.slug);
|
|
|
|
},
|
|
|
|
updateClipboard() {
|
|
|
|
const copyText = this.recipeURL;
|
|
|
|
navigator.clipboard.writeText(copyText).then(
|
2021-06-07 23:04:30 +00:00
|
|
|
() => {
|
|
|
|
console.log("Copied to Clipboard", copyText);
|
|
|
|
utils.notify.success("Copied to Clipboard");
|
|
|
|
},
|
|
|
|
() => console.log("Copied Failed", copyText)
|
|
|
|
);
|
2021-05-02 04:46:02 +00:00
|
|
|
},
|
|
|
|
},
|
2021-06-07 23:04:30 +00:00
|
|
|
};
|
2021-05-02 04:46:02 +00:00
|
|
|
</script>
|