mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
recipe list and slots for it
This commit is contained in:
parent
3b485d59f0
commit
a8d4c43467
2 changed files with 107 additions and 123 deletions
|
@ -51,141 +51,121 @@
|
||||||
</v-list>
|
</v-list>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
import { useFraction } from "~/composables/recipes/use-fraction";
|
import { useFraction } from "~/composables/recipes/use-fraction";
|
||||||
import type { ShoppingListItemOut } from "~/lib/api/types/household";
|
import type { ShoppingListItemOut } from "~/lib/api/types/household";
|
||||||
import type { RecipeSummary } from "~/lib/api/types/recipe";
|
import type { RecipeSummary } from "~/lib/api/types/recipe";
|
||||||
|
|
||||||
export default defineNuxtComponent({
|
interface Props {
|
||||||
props: {
|
recipes: RecipeSummary[];
|
||||||
recipes: {
|
listItem?: ShoppingListItemOut;
|
||||||
type: Array as () => RecipeSummary[],
|
small?: boolean;
|
||||||
required: true,
|
tile?: boolean;
|
||||||
},
|
showDescription?: boolean;
|
||||||
listItem: {
|
disabled?: boolean;
|
||||||
type: Object as () => ShoppingListItemOut | undefined,
|
}
|
||||||
default: undefined,
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
},
|
listItem: undefined,
|
||||||
small: {
|
small: false,
|
||||||
type: Boolean,
|
tile: false,
|
||||||
default: false,
|
showDescription: false,
|
||||||
},
|
disabled: false,
|
||||||
tile: {
|
});
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
showDescription: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
disabled: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
setup(props) {
|
|
||||||
const $auth = useMealieAuth();
|
|
||||||
const { frac } = useFraction();
|
|
||||||
const route = useRoute();
|
|
||||||
const groupSlug = computed(() => route.params.groupSlug || $auth.user?.value?.groupSlug || "");
|
|
||||||
|
|
||||||
const attrs = computed(() => {
|
const $auth = useMealieAuth();
|
||||||
return props.small
|
const { frac } = useFraction();
|
||||||
? {
|
const route = useRoute();
|
||||||
class: {
|
const groupSlug = computed(() => route.params.groupSlug || $auth.user?.value?.groupSlug || "");
|
||||||
sheet: props.tile ? "mb-1 me-1 justify-center align-center" : "mb-1 justify-center align-center",
|
|
||||||
listItem: "px-0",
|
|
||||||
avatar: "ma-0",
|
|
||||||
icon: "ma-0 pa-0 primary",
|
|
||||||
text: "pa-0",
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
text: {
|
|
||||||
title: "font-size: small;",
|
|
||||||
subTitle: "font-size: x-small;",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
class: {
|
|
||||||
sheet: props.tile ? "mx-1 justify-center align-center" : "mb-1 justify-center align-center",
|
|
||||||
listItem: "px-4",
|
|
||||||
avatar: "",
|
|
||||||
icon: "pa-1 primary",
|
|
||||||
text: "",
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
text: {
|
|
||||||
title: "",
|
|
||||||
subTitle: "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
function sanitizeHTML(rawHtml: string) {
|
const attrs = computed(() => {
|
||||||
return DOMPurify.sanitize(rawHtml, {
|
return props.small
|
||||||
USE_PROFILES: { html: true },
|
? {
|
||||||
ALLOWED_TAGS: ["strong", "sup"],
|
class: {
|
||||||
});
|
sheet: props.tile ? "mb-1 me-1 justify-center align-center" : "mb-1 justify-center align-center",
|
||||||
|
listItem: "px-0",
|
||||||
|
avatar: "ma-0",
|
||||||
|
icon: "ma-0 pa-0 primary",
|
||||||
|
text: "pa-0",
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
text: {
|
||||||
|
title: "font-size: small;",
|
||||||
|
subTitle: "font-size: x-small;",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
class: {
|
||||||
|
sheet: props.tile ? "mx-1 justify-center align-center" : "mb-1 justify-center align-center",
|
||||||
|
listItem: "px-4",
|
||||||
|
avatar: "",
|
||||||
|
icon: "pa-1 primary",
|
||||||
|
text: "",
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
text: {
|
||||||
|
title: "",
|
||||||
|
subTitle: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
function sanitizeHTML(rawHtml: string) {
|
||||||
|
return DOMPurify.sanitize(rawHtml, {
|
||||||
|
USE_PROFILES: { html: true },
|
||||||
|
ALLOWED_TAGS: ["strong", "sup"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const listItemDescriptions = computed<string[]>(() => {
|
||||||
|
if (
|
||||||
|
props.recipes.length === 1 // we don't need to specify details if there's only one recipe ref
|
||||||
|
|| !props.listItem?.recipeReferences
|
||||||
|
|| props.listItem.recipeReferences.length !== props.recipes.length
|
||||||
|
) {
|
||||||
|
return props.recipes.map(_ => "");
|
||||||
|
}
|
||||||
|
|
||||||
|
const listItemDescriptions: string[] = [];
|
||||||
|
for (let i = 0; i < props.recipes.length; i++) {
|
||||||
|
const itemRef = props.listItem?.recipeReferences[i];
|
||||||
|
const quantity = (itemRef.recipeQuantity || 1) * (itemRef.recipeScale || 1);
|
||||||
|
|
||||||
|
let listItemDescription = "";
|
||||||
|
if (props.listItem.unit?.fraction) {
|
||||||
|
const fraction = frac(quantity, 10, true);
|
||||||
|
if (fraction[0] !== undefined && fraction[0] > 0) {
|
||||||
|
listItemDescription += fraction[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fraction[1] > 0) {
|
||||||
|
listItemDescription += ` <sup>${fraction[1]}</sup>⁄<sub>${fraction[2]}</sub>`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
listItemDescription = (quantity).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
listItemDescription = (Math.round(quantity * 100) / 100).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
const listItemDescriptions = computed<string[]>(() => {
|
if (props.listItem.unit) {
|
||||||
if (
|
const unitDisplay = props.listItem.unit.useAbbreviation && props.listItem.unit.abbreviation
|
||||||
props.recipes.length === 1 // we don't need to specify details if there's only one recipe ref
|
? props.listItem.unit.abbreviation
|
||||||
|| !props.listItem?.recipeReferences
|
: props.listItem.unit.name;
|
||||||
|| props.listItem.recipeReferences.length !== props.recipes.length
|
|
||||||
) {
|
|
||||||
return props.recipes.map(_ => "");
|
|
||||||
}
|
|
||||||
|
|
||||||
const listItemDescriptions: string[] = [];
|
listItemDescription += ` ${unitDisplay}`;
|
||||||
for (let i = 0; i < props.recipes.length; i++) {
|
}
|
||||||
const itemRef = props.listItem?.recipeReferences[i];
|
|
||||||
const quantity = (itemRef.recipeQuantity || 1) * (itemRef.recipeScale || 1);
|
|
||||||
|
|
||||||
let listItemDescription = "";
|
if (itemRef.recipeNote) {
|
||||||
if (props.listItem.unit?.fraction) {
|
listItemDescription += `, ${itemRef.recipeNote}`;
|
||||||
const fraction = frac(quantity, 10, true);
|
}
|
||||||
if (fraction[0] !== undefined && fraction[0] > 0) {
|
|
||||||
listItemDescription += fraction[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fraction[1] > 0) {
|
listItemDescriptions.push(sanitizeHTML(listItemDescription));
|
||||||
listItemDescription += ` <sup>${fraction[1]}</sup>⁄<sub>${fraction[2]}</sub>`;
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
listItemDescription = (quantity).toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
listItemDescription = (Math.round(quantity * 100) / 100).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.listItem.unit) {
|
return listItemDescriptions;
|
||||||
const unitDisplay = props.listItem.unit.useAbbreviation && props.listItem.unit.abbreviation
|
|
||||||
? props.listItem.unit.abbreviation
|
|
||||||
: props.listItem.unit.name;
|
|
||||||
|
|
||||||
listItemDescription += ` ${unitDisplay}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemRef.recipeNote) {
|
|
||||||
listItemDescription += `, ${itemRef.recipeNote}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
listItemDescriptions.push(sanitizeHTML(listItemDescription));
|
|
||||||
}
|
|
||||||
|
|
||||||
return listItemDescriptions;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
attrs,
|
|
||||||
groupSlug,
|
|
||||||
listItemDescriptions,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -371,6 +371,8 @@
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="recipe"
|
v-if="recipe"
|
||||||
icon
|
icon
|
||||||
|
flat
|
||||||
|
class="bg-transparent"
|
||||||
:disabled="isOffline"
|
:disabled="isOffline"
|
||||||
@click.prevent="removeRecipeReferenceToList(recipe.id!)"
|
@click.prevent="removeRecipeReferenceToList(recipe.id!)"
|
||||||
>
|
>
|
||||||
|
@ -386,6 +388,8 @@
|
||||||
<v-btn
|
<v-btn
|
||||||
icon
|
icon
|
||||||
:disabled="isOffline"
|
:disabled="isOffline"
|
||||||
|
flat
|
||||||
|
class="bg-transparent"
|
||||||
@click.prevent="addRecipeReferenceToList(recipe.id!)"
|
@click.prevent="addRecipeReferenceToList(recipe.id!)"
|
||||||
>
|
>
|
||||||
<v-icon color="grey-lighten-1">
|
<v-icon color="grey-lighten-1">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue