2024-01-13 02:00:15 +00:00
|
|
|
<template>
|
2025-10-18 02:08:22 +00:00
|
|
|
<div class="meal-card">
|
|
|
|
|
<h3>{{ mealTitle }}</h3>
|
|
|
|
|
<h4>
|
|
|
|
|
{{ dayOfWeek }} <small>{{ date }}</small>
|
|
|
|
|
</h4>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Cooked by
|
2025-10-18 03:16:34 +00:00
|
|
|
<span
|
|
|
|
|
v-for="(chef, index) in meal.chefs"
|
|
|
|
|
:key="chef.id"
|
|
|
|
|
>
|
2025-10-18 02:08:22 +00:00
|
|
|
{{ chef.name }}{{ englishSeperator(index, meal.chefs) }}
|
|
|
|
|
</span>
|
|
|
|
|
<span v-if="!meal.chefs.length">somebody?</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
For
|
2025-10-18 03:16:34 +00:00
|
|
|
<span
|
|
|
|
|
v-for="(consumer, index) in meal.consumers"
|
|
|
|
|
:key="consumer.id"
|
|
|
|
|
>
|
2025-10-18 02:08:22 +00:00
|
|
|
{{ consumer.name }}{{ englishSeperator(index, meal.consumers) }}
|
|
|
|
|
</span>
|
|
|
|
|
<span v-if="!meal.consumers.length">somebody?</span>
|
|
|
|
|
</p>
|
2025-10-18 03:16:34 +00:00
|
|
|
<p v-if="meal.purchase_date">
|
|
|
|
|
Purchased {{ ago(meal.purchase_date) }}
|
|
|
|
|
</p>
|
2025-10-18 02:08:22 +00:00
|
|
|
</div>
|
2024-01-13 02:00:15 +00:00
|
|
|
</template>
|
|
|
|
|
|
2025-10-18 02:39:25 +00:00
|
|
|
<script setup>
|
|
|
|
|
import { computed } from 'vue'
|
2024-10-15 08:40:06 +00:00
|
|
|
import { ago } from '@/dateformats.js'
|
|
|
|
|
|
2025-10-18 02:39:25 +00:00
|
|
|
const props = defineProps({
|
|
|
|
|
meal: { type: Object, required: true },
|
|
|
|
|
})
|
|
|
|
|
|
2024-10-16 07:30:45 +00:00
|
|
|
function englishSeperator(index, list) {
|
2025-10-18 02:08:22 +00:00
|
|
|
switch (index) {
|
|
|
|
|
case list.length - 1:
|
|
|
|
|
return ''
|
|
|
|
|
case list.length - 2:
|
|
|
|
|
return ' and '
|
|
|
|
|
default:
|
|
|
|
|
return ', '
|
|
|
|
|
}
|
2024-10-16 07:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function englishList(list) {
|
2025-10-18 02:08:22 +00:00
|
|
|
switch (list.length) {
|
|
|
|
|
case 0:
|
|
|
|
|
return ''
|
|
|
|
|
case 1:
|
|
|
|
|
return list[0]
|
|
|
|
|
case 2:
|
|
|
|
|
return `${list[0]} and ${list[1]}`
|
|
|
|
|
default:
|
|
|
|
|
return `${list.slice(0, -1).join(', ')}, and ${list.slice(-1)}`
|
|
|
|
|
}
|
2024-10-16 07:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-10-18 02:39:25 +00:00
|
|
|
const date = computed(() =>
|
|
|
|
|
props.meal.suggested_date.toLocaleDateString('en-au', {
|
|
|
|
|
month: 'numeric',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
})
|
|
|
|
|
)
|
2024-10-16 07:30:45 +00:00
|
|
|
|
2025-10-18 02:39:25 +00:00
|
|
|
const dayOfWeek = computed(() =>
|
|
|
|
|
props.meal.suggested_date.toLocaleDateString('en-au', { weekday: 'long' })
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const mealTitle = computed(() => {
|
|
|
|
|
const recipesText = englishList(props.meal.recipes.map((mr) => mr.recipe.name))
|
|
|
|
|
const ingredientsText = englishList(props.meal.extra_ingredients.map((i) => i.name))
|
|
|
|
|
|
|
|
|
|
if (recipesText && ingredientsText) return `${recipesText} with ${ingredientsText}`
|
|
|
|
|
if (recipesText || ingredientsText) return recipesText || ingredientsText
|
|
|
|
|
return 'Nothing planned'
|
|
|
|
|
})
|
2025-10-18 02:08:22 +00:00
|
|
|
</script>
|
2025-10-18 03:16:34 +00:00
|
|
|
|
|
|
|
|
<style></style>
|