Release Drafter / auto_label (push) Skipped
Release Drafter / draft_release (push) Canceled after 0s
CodeQL / Analyze (javascript-typescript) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
Backend Lint and Test / tests (sqlite) (push) Canceled after 0s
Backend Lint and Test / tests (postgres) (push) Canceled after 0s
Docker Nightly Production / Backend Server Tests (push) Canceled after 0s
Frontend Lint and Test / lint (push) Canceled after 0s
Docker Nightly Production / Frontend Tests (push) Canceled after 0s
Build Package / Build frontend and wheel (push) Canceled after 0s
Docker Nightly Production / Build Package (push) Canceled after 0s
Docker Nightly Production / Build E2E Image Cache (push) Canceled after 0s
Docker Nightly Production / Build Tagged Release (push) Canceled after 0s
Docker Nightly Production / Notify Discord (push) Canceled after 0s
179 lines
4.8 KiB
Vue
179 lines
4.8 KiB
Vue
<template>
|
|
<div v-if="value && value.length > 0">
|
|
<div
|
|
v-if="!isCookMode"
|
|
class="d-flex justify-start"
|
|
>
|
|
<h2 class="mt-1 text-h5 font-weight-medium opacity-80">
|
|
{{ $t("recipe.ingredients") }}
|
|
</h2>
|
|
<AppButtonCopy
|
|
btn-class="ml-auto"
|
|
:copy-text="ingredientCopyText"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<div
|
|
v-for="(ingredient, index) in value"
|
|
:key="'ingredient' + index"
|
|
>
|
|
<h3
|
|
v-if="showTitleEditor[index]"
|
|
class="mt-4 mb-0"
|
|
>
|
|
{{ ingredient.title }}
|
|
</h3>
|
|
<v-divider v-if="showTitleEditor[index]" class="my-2" />
|
|
<v-list-item
|
|
density="compact"
|
|
class="px-0 py-1 ingredient-list-item"
|
|
@click.stop="toggleChecked(index)"
|
|
>
|
|
<template #prepend>
|
|
<v-checkbox
|
|
:model-value="isChecked(index)"
|
|
:aria-label="parseIngredientText(ingredient, scale, false, isExplicitZero(ingredient))"
|
|
hide-details
|
|
class="pt-0 mt-0"
|
|
color="secondary"
|
|
density="comfortable"
|
|
@click.stop
|
|
@update:model-value="setChecked(index, !!$event)"
|
|
/>
|
|
</template>
|
|
<v-list-item-title>
|
|
<RecipeIngredientListItem
|
|
:ingredient="ingredient"
|
|
:scale="scale"
|
|
:show-zero="isExplicitZero(ingredient)"
|
|
show-substitutions
|
|
/>
|
|
</v-list-item-title>
|
|
</v-list-item>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import RecipeIngredientListItem from "./RecipeIngredientListItem.vue";
|
|
import { useSessionStorage } from "@vueuse/core";
|
|
import { useIngredientTextParser } from "~/composables/recipes";
|
|
import type { RecipeIngredient } from "~/lib/api/types/recipe";
|
|
|
|
interface Props {
|
|
value?: RecipeIngredient[];
|
|
scale?: number;
|
|
isCookMode?: boolean;
|
|
storageKey?: string;
|
|
portionKey?: string;
|
|
portionReferenceIds?: string[];
|
|
portionAllocationIds?: (string | null)[];
|
|
zeroPortionReferenceIds?: string[];
|
|
}
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
value: () => [],
|
|
scale: 1,
|
|
isCookMode: false,
|
|
storageKey: undefined,
|
|
portionKey: undefined,
|
|
portionReferenceIds: () => [],
|
|
portionAllocationIds: () => [],
|
|
zeroPortionReferenceIds: () => [],
|
|
});
|
|
|
|
const { parseIngredientText } = useIngredientTextParser();
|
|
|
|
function isExplicitZero(ingredient: RecipeIngredient) {
|
|
return !!ingredient.referenceId && props.zeroPortionReferenceIds.includes(ingredient.referenceId);
|
|
}
|
|
|
|
function validateTitle(title?: string | null) {
|
|
return !(title === undefined || title === "" || title === null);
|
|
}
|
|
|
|
const transientChecked = ref<Record<string, boolean>>({});
|
|
const sessionChecked = props.storageKey
|
|
? useSessionStorage<Record<string, boolean>>(props.storageKey, {})
|
|
: null;
|
|
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.scale, false));
|
|
});
|
|
|
|
return components.join("\n");
|
|
});
|
|
|
|
function toggleChecked(index: number) {
|
|
setChecked(index, !isChecked(index));
|
|
}
|
|
|
|
function checkedState() {
|
|
return sessionChecked?.value ?? transientChecked.value;
|
|
}
|
|
|
|
function checkedKey(index: number) {
|
|
const allocationId = props.portionAllocationIds[index];
|
|
if (props.portionKey && allocationId) return `allocation:${allocationId}`;
|
|
const referenceId = props.value[index]?.referenceId;
|
|
const key = referenceId ? `ref:${referenceId}` : `idx:${index}`;
|
|
return props.portionKey && referenceId && props.portionReferenceIds.includes(referenceId)
|
|
? `step:${props.portionKey}:${key}`
|
|
: key;
|
|
}
|
|
|
|
function isChecked(index: number) {
|
|
return !!checkedState()[checkedKey(index)];
|
|
}
|
|
|
|
function setChecked(index: number, value: boolean) {
|
|
const state = checkedState();
|
|
state[checkedKey(index)] = value;
|
|
|
|
if (sessionChecked) {
|
|
sessionChecked.value = { ...state };
|
|
}
|
|
else {
|
|
transientChecked.value = { ...state };
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.dense-markdown p {
|
|
margin: auto !important;
|
|
}
|
|
|
|
/* vuetify clips both of these, which would swallow the substitution button's tap target
|
|
where it reaches past the line of text */
|
|
.ingredient-list-item .v-list-item__content,
|
|
.ingredient-list-item .v-list-item-title {
|
|
overflow: visible;
|
|
}
|
|
|
|
.ingredient-list-item {
|
|
align-items: flex-start;
|
|
}
|
|
|
|
.ingredient-list-item .v-list-item__prepend,
|
|
.ingredient-list-item .v-list-item__content {
|
|
align-self: flex-start;
|
|
}
|
|
|
|
.ingredient-list-item .v-selection-control {
|
|
align-self: flex-start;
|
|
margin-top: -9px;
|
|
}
|
|
</style>
|