1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-31 02:59:42 +02:00
mealie/frontend/src/components/Recipe/FavoriteBadge.vue
Hayden 2b97af5728
feature/recipe-comments (#448)
* fix favorite color issue

* db and models for comments

* rename files

* initial UI for comments

* fix format

* import / export

* fixes #428

* format

Co-authored-by: hay-kot <hay-kot@pm.me>
2021-05-29 20:50:17 -08:00

54 lines
No EOL
1.1 KiB
Vue

<template>
<v-btn
small
@click.prevent="toggleFavorite"
v-if="isFavorite || showAlways"
:color="buttonStyle ? 'primary' : 'secondary'"
:icon="!buttonStyle"
:fab="buttonStyle"
>
<v-icon :small="!buttonStyle" color="secondary">
{{ isFavorite ? "mdi-heart" : "mdi-heart-outline" }}
</v-icon>
</v-btn>
</template>
<script>
import { api } from "@/api";
export default {
props: {
slug: {
default: "",
},
showAlways: {
type: Boolean,
default: false,
},
buttonStyle: {
type: Boolean,
default: false,
},
},
computed: {
user() {
return this.$store.getters.getUserData;
},
isFavorite() {
return this.user.favoriteRecipes.indexOf(this.slug) !== -1;
},
},
methods: {
async toggleFavorite() {
if (!this.isFavorite) {
await api.users.addFavorite(this.user.id, this.slug);
} else {
await api.users.removeFavorite(this.user.id, this.slug);
}
this.$store.dispatch("requestUserData");
},
},
};
</script>
<style lang="scss" scoped>
</style>