2024-05-11 06:03:29 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2024-05-18 03:49:43 +00:00
|
|
|
<h1>My Shopping List</h1>
|
2024-05-18 07:05:28 +00:00
|
|
|
<router-link :to="`/shopping/current`">Full Shopping List</router-link>
|
2024-05-18 04:46:27 +00:00
|
|
|
<editable-ingredients-panel @on-add="addIngredient" @on-delete="deleteIngredient" @on-update-ingredient="updateIngredient" @on-editing="onEditing" :ingredients="ingredients" />
|
2024-05-11 06:03:29 +00:00
|
|
|
</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>
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-10-18 01:36:55 +00:00
|
|
|
import { getMyShoppingList, saveMyShoppingList } from '@/api/shopping'
|
2025-10-18 01:42:23 +00:00
|
|
|
import { useAuth } from '@/composables/useAuth'
|
2024-05-12 06:32:28 +00:00
|
|
|
|
|
|
|
|
import EditableIngredientsPanel from '@/components/ingredients/EditableIngredientsPanel.vue'
|
2024-05-11 06:03:29 +00:00
|
|
|
|
|
|
|
|
export default {
|
2024-05-18 03:49:43 +00:00
|
|
|
name: 'MyShoppingpage',
|
2024-05-18 04:46:27 +00:00
|
|
|
components: { EditableIngredientsPanel },
|
2024-05-11 06:03:29 +00:00
|
|
|
data() {
|
2024-05-18 04:46:27 +00:00
|
|
|
return { ingredients: [], person: null }
|
2024-05-12 03:32:18 +00:00
|
|
|
},
|
2024-05-13 03:45:46 +00:00
|
|
|
async beforeMount() {
|
2025-10-18 01:42:23 +00:00
|
|
|
const { loadUser } = useAuth()
|
|
|
|
|
const person = await loadUser()
|
2024-05-13 03:45:46 +00:00
|
|
|
if (!person)
|
|
|
|
|
return this.$router.push({ name: 'login' });
|
|
|
|
|
|
|
|
|
|
this.person = person;
|
2024-05-18 04:46:27 +00:00
|
|
|
await this.updateShoppingList();
|
2024-05-13 03:45:46 +00:00
|
|
|
},
|
2024-05-12 03:32:18 +00:00
|
|
|
methods: {
|
2024-05-18 04:46:27 +00:00
|
|
|
async updateShoppingList(save = false) {
|
2025-07-28 23:22:58 +00:00
|
|
|
const new_ingredients = save ?
|
2025-10-18 01:36:55 +00:00
|
|
|
await saveMyShoppingList(this.ingredients) :
|
|
|
|
|
await getMyShoppingList();
|
2024-05-13 03:45:46 +00:00
|
|
|
|
2025-07-28 23:22:58 +00:00
|
|
|
this.ingredients = new_ingredients;
|
2024-05-12 06:32:28 +00:00
|
|
|
},
|
2024-05-13 03:45:46 +00:00
|
|
|
addIngredient() {
|
2024-05-20 12:16:39 +00:00
|
|
|
this.ingredients = [{ id: -1 }, ...this.ingredients];
|
2024-05-12 06:32:28 +00:00
|
|
|
},
|
2024-05-13 03:45:46 +00:00
|
|
|
deleteIngredient(ingredient) {
|
2024-05-18 04:46:27 +00:00
|
|
|
this.ingredients = this.ingredients.filter(i => i !== ingredient);
|
2024-05-12 06:32:28 +00:00
|
|
|
},
|
2024-05-13 03:45:46 +00:00
|
|
|
updateIngredient(oldIngredient, newIngredient) {
|
2024-05-18 04:46:27 +00:00
|
|
|
this.ingredients = this.ingredients.map(source => source === oldIngredient ? newIngredient : source);
|
|
|
|
|
},
|
|
|
|
|
async onEditing(isStartingEdit) {
|
|
|
|
|
await this.updateShoppingList(!isStartingEdit);
|
2024-05-12 06:32:28 +00:00
|
|
|
|
2024-05-18 04:46:27 +00:00
|
|
|
if (isStartingEdit && this.ingredients.length === 0) {
|
|
|
|
|
this.addIngredient();
|
|
|
|
|
}
|
2024-05-11 06:03:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|