feat: fix recipe rating overwriting (#1756)

Previously, the recipe-ratings component would not sync to the v-modeled value when doing it's own updating. This PR fixes that issue and ensures that the value is pushed up to the parent whether in emit only mode or not.
This commit is contained in:
Hayden 2022-10-22 12:54:47 -08:00 committed by GitHub
parent ce4315f971
commit 2e11e57e0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 10 deletions

View File

@ -4,8 +4,8 @@
<v-card v-if="!landscape" width="50%" flat class="d-flex flex-column justify-center align-center">
<v-card-text>
<v-card-title class="headline pa-0 flex-column align-center">
{{ recipe.name }}
<RecipeRating :key="recipe.slug" :value="recipe.rating" :name="recipe.name" :slug="recipe.slug" />
{{ recipe.name }} {{ recipe.rating }}
<RecipeRating :key="recipe.slug" v-model="recipe.rating" :name="recipe.name" :slug="recipe.slug" />
</v-card-title>
<v-divider class="my-2"></v-divider>
<SafeMarkdown :source="recipe.description" />

View File

@ -19,7 +19,7 @@
<RecipeRating
v-if="landscape && $vuetify.breakpoint.smAndUp"
:key="recipe.slug"
:value="recipe.rating"
:v-model="recipe.rating"
:name="recipe.name"
:slug="recipe.slug"
/>

View File

@ -15,7 +15,7 @@
<RecipeRating
v-if="$vuetify.breakpoint.smAndDown"
:key="recipe.slug"
:value="recipe.rating"
v-model="recipe.rating"
:name="recipe.name"
:slug="recipe.slug"
/>

View File

@ -53,14 +53,13 @@ export default defineComponent({
const api = useUserApi();
function updateRating(val: number) {
if (props.emitOnly) {
context.emit("input", val);
return;
}
if (!props.emitOnly) {
api.recipes.patchOne(props.slug, {
rating: val,
});
}
context.emit("input", val);
}
return { loggedIn, rating, updateRating };
},