munch-ease-frontend/src/components/shopping/MyShoppingPage.vue

81 lines
2.6 KiB
Vue
Raw Normal View History

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>
2025-10-18 02:01:18 +00:00
<script setup>
import { ref, onBeforeMount } from 'vue'
import { useRouter } from 'vue-router'
2025-10-18 01:42:23 +00:00
import { useAuth } from '@/composables/useAuth'
2025-10-18 02:01:18 +00:00
import { useShopping } from '@/composables/useShopping'
2024-05-12 06:32:28 +00:00
import EditableIngredientsPanel from '@/components/ingredients/EditableIngredientsPanel.vue'
2024-05-11 06:03:29 +00:00
2024-05-13 03:45:46 +00:00
2025-10-18 02:01:18 +00:00
const router = useRouter()
const { loadUser } = useAuth()
const { getMyShoppingList, saveMyShoppingList } = useShopping()
const person = ref(null)
const ingredients = ref([])
async function updateShoppingList(save = false) {
const newIngredients = save ? await saveMyShoppingList(ingredients.value) : await getMyShoppingList()
ingredients.value = newIngredients
}
function addIngredient() {
ingredients.value = [{ id: -1 }, ...ingredients.value]
}
function deleteIngredient(ingredient) {
ingredients.value = ingredients.value.filter((i) => i !== ingredient)
}
2024-05-13 03:45:46 +00:00
2025-10-18 02:01:18 +00:00
function updateIngredient(oldIngredient, newIngredient) {
ingredients.value = ingredients.value.map((source) => (source === oldIngredient ? newIngredient : source))
}
2024-05-12 06:32:28 +00:00
2025-10-18 02:01:18 +00:00
async function onEditing(isStartingEdit) {
await updateShoppingList(!isStartingEdit)
if (isStartingEdit && ingredients.value.length === 0) addIngredient()
2024-05-11 06:03:29 +00:00
}
2025-10-18 02:01:18 +00:00
onBeforeMount(async () => {
const u = await loadUser()
if (!u) return router.push({ name: 'login' })
person.value = u
await updateShoppingList()
})
2024-05-11 06:03:29 +00:00
</script>