mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-21 22:13:31 -07:00
ingredients
This commit is contained in:
parent
f2ffa154c6
commit
c67acbd5c5
1 changed files with 42 additions and 60 deletions
|
@ -53,71 +53,53 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import RecipeIngredientListItem from "./RecipeIngredientListItem.vue";
|
import RecipeIngredientListItem from "./RecipeIngredientListItem.vue";
|
||||||
import { parseIngredientText } from "~/composables/recipes";
|
import { parseIngredientText } from "~/composables/recipes";
|
||||||
import type { RecipeIngredient } from "~/lib/api/types/recipe";
|
import type { RecipeIngredient } from "~/lib/api/types/recipe";
|
||||||
|
|
||||||
export default defineNuxtComponent({
|
interface Props {
|
||||||
components: { RecipeIngredientListItem },
|
value?: RecipeIngredient[];
|
||||||
props: {
|
disableAmount?: boolean;
|
||||||
value: {
|
scale?: number;
|
||||||
type: Array as () => RecipeIngredient[],
|
isCookMode?: boolean;
|
||||||
default: () => [],
|
}
|
||||||
},
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
disableAmount: {
|
value: () => [],
|
||||||
type: Boolean,
|
disableAmount: false,
|
||||||
default: false,
|
scale: 1,
|
||||||
},
|
isCookMode: false,
|
||||||
scale: {
|
|
||||||
type: Number,
|
|
||||||
default: 1,
|
|
||||||
},
|
|
||||||
isCookMode: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
setup(props) {
|
|
||||||
function validateTitle(title?: string) {
|
|
||||||
return !(title === undefined || title === "" || title === null);
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = reactive({
|
|
||||||
checked: props.value.map(() => false),
|
|
||||||
showTitleEditor: computed(() => props.value.map(x => validateTitle(x.title))),
|
|
||||||
});
|
|
||||||
|
|
||||||
const ingredientCopyText = computed(() => {
|
|
||||||
const components: string[] = [];
|
|
||||||
props.value.forEach((ingredient) => {
|
|
||||||
if (ingredient.title) {
|
|
||||||
if (components.length) {
|
|
||||||
components.push("");
|
|
||||||
}
|
|
||||||
|
|
||||||
components.push(`[${ingredient.title}]`);
|
|
||||||
}
|
|
||||||
|
|
||||||
components.push(parseIngredientText(ingredient, props.disableAmount, props.scale, false));
|
|
||||||
});
|
|
||||||
|
|
||||||
return components.join("\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
function toggleChecked(index: number) {
|
|
||||||
// TODO Find a better way to do this - $set is not available, and
|
|
||||||
// direct array modifications are not propagated for some reason
|
|
||||||
state.checked.splice(index, 1, !state.checked[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...toRefs(state),
|
|
||||||
ingredientCopyText,
|
|
||||||
toggleChecked,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function validateTitle(title?: string | null) {
|
||||||
|
return !(title === undefined || title === "" || title === null);
|
||||||
|
}
|
||||||
|
|
||||||
|
const checked = ref(props.value.map(() => false));
|
||||||
|
const showTitleEditor = computed(() => props.value.map(x => validateTitle(x.title)));
|
||||||
|
|
||||||
|
const ingredientCopyText = computed(() => {
|
||||||
|
const components: string[] = [];
|
||||||
|
props.value.forEach((ingredient) => {
|
||||||
|
if (ingredient.title) {
|
||||||
|
if (components.length) {
|
||||||
|
components.push("");
|
||||||
|
}
|
||||||
|
|
||||||
|
components.push(`[${ingredient.title}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
components.push(parseIngredientText(ingredient, props.disableAmount, props.scale, false));
|
||||||
|
});
|
||||||
|
|
||||||
|
return components.join("\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
function toggleChecked(index: number) {
|
||||||
|
// TODO Find a better way to do this - $set is not available, and
|
||||||
|
// direct array modifications are not propagated for some reason
|
||||||
|
checked.value.splice(index, 1, !checked.value[index]);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue