2024-05-11 06:03:29 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<h1>Shopping List</h1>
|
2024-05-12 03:32:18 +00:00
|
|
|
<h4>Included Meals</h4>
|
|
|
|
|
<meal-selection-list @meal-selected="mealSelected" @meal-unselected="mealUnselected" />
|
2024-05-12 06:32:28 +00:00
|
|
|
<h4>My Requests</h4>
|
|
|
|
|
<editable-ingredients-panel @on-add="addIngredient" @on-delete="deleteIngredient" @on-update-ingredient="updateIngredient" :ingredients="mySources" />
|
|
|
|
|
|
|
|
|
|
<h4>Full shopping list</h4>
|
|
|
|
|
<ul class="full-shopping-list">
|
2024-05-11 06:03:29 +00:00
|
|
|
<li v-for="item in shoppingList" :key="item.id">
|
|
|
|
|
<shopping-list-item :product="item.product" :sources="item.sources" />
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
# Functions
|
|
|
|
|
* Add a random item to next shop
|
|
|
|
|
* Add meals to next shop
|
|
|
|
|
* Show cards for the next 7 meals
|
|
|
|
|
* Slider / drawer for more meals
|
|
|
|
|
* Check meal to add
|
|
|
|
|
* Update shopping list automatically as meals change
|
|
|
|
|
* Visual indicator for meals that are already in the list
|
|
|
|
|
* Visual indicator for purchased meals
|
|
|
|
|
* Aggregate items from meals and random items into a single list of products
|
|
|
|
|
* For each product, need to have visibility of
|
|
|
|
|
* Name
|
|
|
|
|
* Link
|
|
|
|
|
* Image
|
|
|
|
|
* Quantity
|
|
|
|
|
* Source meal / person
|
|
|
|
|
* Date added / for
|
|
|
|
|
* Need to be able to mark list as done
|
|
|
|
|
* Keeps history - track purchased meals
|
|
|
|
|
* Clears list
|
|
|
|
|
|
|
|
|
|
* History view of purchased lists (seperate page ofc)
|
|
|
|
|
-->
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
2024-05-12 06:32:28 +00:00
|
|
|
.full-shopping-list li {
|
2024-05-11 06:03:29 +00:00
|
|
|
list-style-type: none;
|
|
|
|
|
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 0.5em;
|
|
|
|
|
margin-bottom: 1em;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-12 06:32:28 +00:00
|
|
|
.full-shopping-list {
|
2024-05-11 06:03:29 +00:00
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-05-12 06:32:28 +00:00
|
|
|
import data from '@/data.js'
|
|
|
|
|
|
|
|
|
|
import EditableIngredientsPanel from '@/components/ingredients/EditableIngredientsPanel.vue'
|
2024-05-11 06:03:29 +00:00
|
|
|
import ShoppingListItem from './ShoppingListItem.vue'
|
|
|
|
|
import MealSelectionList from './MealSelectionList.vue'
|
2024-05-12 06:32:28 +00:00
|
|
|
|
2024-05-12 03:32:18 +00:00
|
|
|
import { mealToShoppingListSources, removeMealFromShoppingListSources, groupByProduct } from './shopping.js'
|
2024-05-11 06:03:29 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'ShoppingPage',
|
2024-05-12 06:32:28 +00:00
|
|
|
components: { ShoppingListItem, MealSelectionList, EditableIngredientsPanel },
|
2024-05-11 06:03:29 +00:00
|
|
|
data() {
|
2024-05-12 06:32:28 +00:00
|
|
|
return { shoppingList: [], sources: [], mySources: [] }
|
2024-05-12 03:32:18 +00:00
|
|
|
},
|
|
|
|
|
watch: {
|
2024-05-12 06:32:28 +00:00
|
|
|
async sources() {
|
2024-05-12 03:32:18 +00:00
|
|
|
this.shoppingList = groupByProduct(this.sources);
|
2024-05-12 06:32:28 +00:00
|
|
|
|
|
|
|
|
const person = await data.currentUser();
|
|
|
|
|
this.mySources = this.sources.filter(source => source.person?.id === person?.id).map(source => source.ingredient);
|
2024-05-12 03:32:18 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
mealSelected(meal) {
|
|
|
|
|
this.sources = this.sources.concat(mealToShoppingListSources(meal));
|
|
|
|
|
},
|
|
|
|
|
mealUnselected(meal) {
|
|
|
|
|
this.sources = removeMealFromShoppingListSources(this.sources, meal);
|
2024-05-12 06:32:28 +00:00
|
|
|
},
|
|
|
|
|
async addIngredient() {
|
|
|
|
|
const person = await data.currentUser();
|
|
|
|
|
if (!person) return;
|
|
|
|
|
|
|
|
|
|
this.sources = this.sources.concat([{ ingredient: { id: 0 }, person }]);
|
|
|
|
|
},
|
|
|
|
|
async deleteIngredient(ingredient) {
|
|
|
|
|
const person = await data.currentUser();
|
|
|
|
|
if (!person) return;
|
|
|
|
|
|
|
|
|
|
const isMatch = source => source.ingredient === ingredient && source.person?.id === person.id;
|
|
|
|
|
this.sources = this.sources.filter(source => !isMatch(source));
|
|
|
|
|
},
|
|
|
|
|
async updateIngredient(oldIngredient, newIngredient) {
|
|
|
|
|
const person = await data.currentUser();
|
|
|
|
|
if (!person) return;
|
|
|
|
|
|
|
|
|
|
this.sources = this.sources.map(source => source.ingredient === oldIngredient ? { ingredient: newIngredient, person } : source);
|
2024-05-11 06:03:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|