2022-08-27 10:44:58 -08:00
|
|
|
<template>
|
|
|
|
<div class="d-flex justify-space-between align-center pt-2 pb-3">
|
2025-06-20 00:09:12 +07:00
|
|
|
<RecipeScaleEditButton
|
|
|
|
v-if="!isEditMode"
|
2025-07-30 20:37:02 +02:00
|
|
|
v-model.number="scale"
|
2025-06-20 00:09:12 +07:00
|
|
|
:recipe-servings="recipeServings"
|
2025-07-31 10:36:24 -05:00
|
|
|
:edit-scale="hasFoodOrUnit && !isEditMode"
|
2025-06-20 00:09:12 +07:00
|
|
|
/>
|
2022-08-27 10:44:58 -08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2025-07-30 20:37:02 +02:00
|
|
|
<script setup lang="ts">
|
2022-08-27 10:44:58 -08:00
|
|
|
import RecipeScaleEditButton from "~/components/Domain/Recipe/RecipeScaleEditButton.vue";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { NoUndefinedField } from "~/lib/api/types/non-generated";
|
|
|
|
import type { Recipe } from "~/lib/api/types/recipe";
|
2022-08-27 10:44:58 -08:00
|
|
|
import { usePageState } from "~/composables/recipe-page/shared-state";
|
2023-08-21 09:54:02 -05:00
|
|
|
|
2025-07-30 20:37:02 +02:00
|
|
|
const props = defineProps<{ recipe: NoUndefinedField<Recipe> }>();
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-07-30 20:37:02 +02:00
|
|
|
const scale = defineModel<number>({ default: 1 });
|
2024-11-20 08:46:27 -06:00
|
|
|
|
2025-07-30 20:37:02 +02:00
|
|
|
const { isEditMode } = usePageState(props.recipe.slug);
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-07-30 20:37:02 +02:00
|
|
|
const recipeServings = computed<number>(() => {
|
|
|
|
return props.recipe.recipeServings || props.recipe.recipeYieldQuantity || 1;
|
2022-08-27 10:44:58 -08:00
|
|
|
});
|
2025-07-31 10:36:24 -05:00
|
|
|
|
|
|
|
const hasFoodOrUnit = computed(() => {
|
|
|
|
if (props.recipe.recipeIngredient) {
|
|
|
|
for (const ingredient of props.recipe.recipeIngredient) {
|
|
|
|
if (ingredient.food || ingredient.unit) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2022-08-27 10:44:58 -08:00
|
|
|
</script>
|