2024-01-13 02:00:15 +00:00
|
|
|
<template>
|
|
|
|
|
<div class="meal-card">
|
|
|
|
|
<h3>{{ dayOfWeek }} <small>{{ date }}</small></h3>
|
2024-01-17 11:31:45 +00:00
|
|
|
|
|
|
|
|
<p v-if="meal.recipes.length && meal.extra_ingredients.length">
|
2024-01-17 11:57:44 +00:00
|
|
|
<span v-for="(recipe, index) in meal.recipes" :key="recipe.id">
|
|
|
|
|
{{ recipe.name }}{{ seperator(index, meal.recipes) }}
|
2024-01-17 11:31:45 +00:00
|
|
|
</span>
|
|
|
|
|
with
|
2024-01-17 11:57:44 +00:00
|
|
|
<span v-for="(ingredient, index) in meal.extra_ingredients" :key="ingredient.id">
|
|
|
|
|
{{ ingredient.name }}{{ seperator(index, meal.extra_ingredients) }}
|
2024-01-17 11:31:45 +00:00
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p v-else-if="meal.recipes.length">
|
2024-01-17 11:57:44 +00:00
|
|
|
<span v-for="(recipe, index) in meal.recipes" :key="recipe.id">
|
|
|
|
|
{{ recipe.name }}{{ seperator(index, meal.recipes) }}
|
2024-01-17 11:31:45 +00:00
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p v-else-if="meal.extra_ingredients.length">
|
2024-01-17 11:57:44 +00:00
|
|
|
<span v-for="(ingredient, index) in meal.extra_ingredients" :key="ingredient.id">
|
|
|
|
|
{{ ingredient.name }}{{ seperator(index, meal.extra_ingredients) }}
|
2024-01-17 11:31:45 +00:00
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p v-else>
|
|
|
|
|
Nothing planned
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Cooked by
|
2024-05-02 11:25:01 +00:00
|
|
|
<span v-for="(chef, index) in meal.chefs" :key="chef.id">
|
2024-01-17 11:57:44 +00:00
|
|
|
{{ chef.name }}{{ seperator(index, meal.chefs) }}
|
2024-01-17 11:31:45 +00:00
|
|
|
</span>
|
|
|
|
|
<span v-if="!meal.chefs.length">somebody?</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
For
|
2024-05-02 11:25:01 +00:00
|
|
|
<span v-for="(consumer, index) in meal.consumers" :key="consumer.id">
|
2024-01-17 11:57:44 +00:00
|
|
|
{{ consumer.name }}{{ seperator(index, meal.consumers) }}
|
2024-01-17 11:31:45 +00:00
|
|
|
</span>
|
|
|
|
|
<span v-if="!meal.consumers.length">somebody?</span>
|
|
|
|
|
</p>
|
2024-05-20 23:57:49 +00:00
|
|
|
<p v-if="meal.purchase_date">
|
|
|
|
|
Purchased {{ formatDate(meal.purchase_date) }}
|
|
|
|
|
</p>
|
2024-01-13 02:00:15 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: 'MealCard',
|
|
|
|
|
props: ['meal'],
|
|
|
|
|
computed: {
|
|
|
|
|
date() {
|
2024-05-25 02:09:27 +00:00
|
|
|
return this.meal.suggested_date.toLocaleDateString('en-au', { month: 'numeric', day: 'numeric' })
|
2024-01-13 02:00:15 +00:00
|
|
|
},
|
|
|
|
|
dayOfWeek() {
|
2024-05-25 02:09:27 +00:00
|
|
|
return this.meal.suggested_date.toLocaleDateString('en-au', { weekday: 'long' })
|
2024-01-17 11:57:44 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
seperator(index, list) {
|
|
|
|
|
switch (index) {
|
|
|
|
|
case list.length - 1:
|
|
|
|
|
return '';
|
|
|
|
|
case list.length - 2:
|
|
|
|
|
return ' and ';
|
|
|
|
|
default:
|
|
|
|
|
return ', ';
|
|
|
|
|
}
|
2024-05-20 23:57:49 +00:00
|
|
|
},
|
|
|
|
|
formatDate(datetime) {
|
|
|
|
|
// If its less than a week, use "2 minutes ago" style
|
|
|
|
|
const diff = new Date() - datetime;
|
|
|
|
|
if (diff < 1000 * 60 * 60 * 24 * 7) {
|
|
|
|
|
const minutes = Math.floor(diff / 1000 / 60);
|
|
|
|
|
if (minutes < 60) {
|
|
|
|
|
return `${minutes} minute${minutes === 1 ? '' : 's'} ago`;
|
|
|
|
|
}
|
|
|
|
|
const hours = Math.floor(minutes / 60);
|
|
|
|
|
if (hours < 24) {
|
|
|
|
|
return `${hours} hour${hours === 1 ? '' : 's'} ago`;
|
|
|
|
|
}
|
|
|
|
|
const days = Math.floor(hours / 24);
|
|
|
|
|
return `${days} day${days === 1 ? '' : 's'} ago`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise, use a date format with the day of week prepended
|
|
|
|
|
return `${datetime.toLocaleDateString('en-au', { weekday: 'long' })} ${datetime.toLocaleDateString('en-au', { month: 'numeric', day: 'numeric' })}`;
|
2024-01-13 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|