diff --git a/src/components/shopping/MealSelectionList.vue b/src/components/shopping/MealSelectionList.vue index faa0643..b68b251 100644 --- a/src/components/shopping/MealSelectionList.vue +++ b/src/components/shopping/MealSelectionList.vue @@ -4,9 +4,9 @@
  • - +
  • @@ -37,17 +37,21 @@ input[type="checkbox"] { label { display: inline-block; - padding: 1em; - width: 10em; - height: 10em; + padding: 0.1vh 0.3em; + /* Help the visibility of the text over the image */ + background-color: rgba(255, 255, 255, 0.9); + border: 3px solid transparent; + border-radius: 0.5em; + margin: 0; + font-weight: normal; + cursor: pointer; + color: #777; } -/* Give the card a thick pastel green stroke when checked */ input[type="checkbox"]:checked + label { - border: 0.5em solid #8FBC8F; - /* Reduce the size to account for the border */ - width: 9em; - height: 9em; + border: 3px solid #3d5447; + color: #3d5447; + text-shadow: #ccc 0 0 0.1em; } /* Show the image as the background image of the card */ @@ -72,6 +76,44 @@ label { import data from '@/data.js' +const nth = (d) => { + if (d > 3 && d < 21) return 'th'; + switch (d % 10) { + case 1: return "st"; + case 2: return "nd"; + case 3: return "rd"; + default: return "th"; + } +}; + +const formatDate = (date) => { + return `${date.toLocaleDateString('en-AU', { weekday: 'short' })} ${date.getDate()}${nth(date.getDate())}` +} + +const getUrl = (meal) => { + // First non empty value in meal.recipe/image_urls + for (const recipe of meal.recipes) { + if (recipe.image_urls.length && recipe.image_urls[0]) { + return recipe.image_urls[0]; + } + } + + // First meal.extra_ingredient with a product with an image + for (const ingredient of meal.extra_ingredients) { + if (ingredient.product) { + if (ingredient.product.img_large) { + return ingredient.product.img_large; + } + + if (ingredient.product.img_small) { + return ingredient.product.img_small; + } + } + } + + return null; +} + export default { name: 'MealSelectionList', data() { @@ -88,38 +130,24 @@ export default { this.meals = meals; }, methods: { + formatDate, getImageStyling(meal) { - let image = null; - // First non empty value in meal.recipe/image_urls - for (const recipe of meal.recipes) { - if (recipe.image_urls.length && recipe.image_urls[0]) { - image = recipe.image_urls[0]; - break; - } - } - - if (!image) { - // First meal.extra_ingredient with a product with an image - for (const ingredient of meal.extra_ingredients) { - if (ingredient.product) { - if (ingredient.product.img_large) { - image = ingredient.product.img_large; - break; - } - - if (ingredient.product.img_small) { - image = ingredient.product.img_small; - break; - } - } - } - } - - if (!image) { + const imageUrl = getUrl(meal); + if (!imageUrl) { return null; } - - return {background: `linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 50%, rgba(255, 255, 255, 0) 100%), url('${image}') center/cover no-repeat` } + + const opacity = 0.7; + return {background: `linear-gradient(to bottom, rgba(255, 255, 255, ${ opacity }) 0%, rgba(255, 255, 255, ${ opacity }) 100%), url('${imageUrl}') center/cover no-repeat`}; + }, + mealCheckChanged(event) { + const mealId = parseInt(event.target.id); + const meal = this.meals.find(m => m.id === mealId); + if (event.target.checked) { + this.$emit('meal-selected', meal); + } else { + this.$emit('meal-unselected', meal); + } } } } diff --git a/src/components/shopping/ShoppingListItem.vue b/src/components/shopping/ShoppingListItem.vue index f0d17d1..a731085 100644 --- a/src/components/shopping/ShoppingListItem.vue +++ b/src/components/shopping/ShoppingListItem.vue @@ -5,20 +5,20 @@

    - {{ product.name }}, {{ quantityRequired }} of {{ product.size }} {{ product.unit }} required. + {{ product.name }}, {{ quantityRequired }} required.

    , and - - {{ source.quantity.value }} {{ source.quantity.unit }} for {{ source.person.name }} + + {{ source.ingredient.quantity }} {{ source.ingredient.unit }} for {{ source.person.name }} - - {{ source.quantity.value }} {{ source.quantity.unit }} + + {{ source.ingredient.quantity }} {{ source.ingredient.unit }} in {{ source.recipe.name }} for {{ source.meal.meal_date.toLocaleDateString("en-AU", { weekday: 'long', month: 'long', day: 'numeric' }) }} - + {{ source.ingredient.line }} for {{ source.meal.meal_date.toLocaleDateString("en-AU", { weekday: 'long', month: 'long', day: 'numeric' }) }} diff --git a/src/components/shopping/ShoppingPage.vue b/src/components/shopping/ShoppingPage.vue index 8cc393f..fb0e1cb 100644 --- a/src/components/shopping/ShoppingPage.vue +++ b/src/components/shopping/ShoppingPage.vue @@ -1,8 +1,8 @@