2021-07-31 23:07:19 +00:00
|
|
|
<template>
|
|
|
|
<div @click.prevent>
|
|
|
|
<v-rating
|
2021-08-02 03:24:47 +00:00
|
|
|
v-model="rating"
|
2021-07-31 23:07:19 +00:00
|
|
|
:readonly="!loggedIn"
|
|
|
|
color="secondary"
|
|
|
|
background-color="secondary lighten-3"
|
|
|
|
length="5"
|
|
|
|
:dense="small ? true : undefined"
|
|
|
|
:size="small ? 15 : undefined"
|
|
|
|
hover
|
|
|
|
:value="value"
|
|
|
|
@input="updateRating"
|
|
|
|
@click="updateRating"
|
|
|
|
></v-rating>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-04 05:38:45 +00:00
|
|
|
import { defineComponent } from "@nuxtjs/composition-api";
|
|
|
|
import { useApiSingleton } from "~/composables/use-api";
|
|
|
|
export default defineComponent({
|
2021-07-31 23:07:19 +00:00
|
|
|
props: {
|
|
|
|
emitOnly: {
|
2021-08-02 03:24:47 +00:00
|
|
|
type: Boolean,
|
2021-07-31 23:07:19 +00:00
|
|
|
default: false,
|
|
|
|
},
|
2021-08-02 03:24:47 +00:00
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
default: "",
|
|
|
|
},
|
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
default: "",
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
|
|
|
},
|
2021-07-31 23:07:19 +00:00
|
|
|
small: {
|
2021-08-02 03:24:47 +00:00
|
|
|
type: Boolean,
|
2021-07-31 23:07:19 +00:00
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
2021-08-04 05:38:45 +00:00
|
|
|
setup() {
|
|
|
|
const api = useApiSingleton();
|
|
|
|
|
|
|
|
return { api };
|
|
|
|
},
|
2021-07-31 23:07:19 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
rating: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
loggedIn() {
|
2021-08-03 06:15:11 +00:00
|
|
|
return this.$auth.loggedIn;
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
|
|
|
},
|
2021-08-02 03:24:47 +00:00
|
|
|
mounted() {
|
|
|
|
this.rating = this.value;
|
|
|
|
},
|
2021-07-31 23:07:19 +00:00
|
|
|
methods: {
|
|
|
|
updateRating(val) {
|
|
|
|
if (this.emitOnly) {
|
|
|
|
this.$emit("input", val);
|
|
|
|
return;
|
|
|
|
}
|
2021-08-04 05:38:45 +00:00
|
|
|
this.api.recipes.patchOne(this.slug, {
|
2021-07-31 23:07:19 +00:00
|
|
|
name: this.name,
|
|
|
|
slug: this.slug,
|
|
|
|
rating: val,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2021-08-04 05:38:45 +00:00
|
|
|
});
|
2021-07-31 23:07:19 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped></style>
|