diff --git a/frontend/src/pages/ShoppingPage.tsx b/frontend/src/pages/ShoppingPage.tsx index 1fb7d16..d1f10b5 100644 --- a/frontend/src/pages/ShoppingPage.tsx +++ b/frontend/src/pages/ShoppingPage.tsx @@ -3,7 +3,7 @@ import { useState, useEffect, useCallback } from 'react' import type { ShoppingList, ShoppingListDetail, ShoppingItem, Store } from '../api/shopping' import { fetchLists, createList, fetchListDetail, updateList, deleteList, - addItem, updateItem, deleteItem, finishShopping, fetchStores, + addItem, updateItem, deleteItem, finishShopping, fetchStores, generateMagicList, } from '../api/shopping' import Modal from '../components/Modal' import ItemRow from '../components/shopping/ItemRow' @@ -44,6 +44,8 @@ export default function ShoppingPage() { const [error, setError] = useState(null) const [showCreateModal, setShowCreateModal] = useState(false) const [showAddItemModal, setShowAddItemModal] = useState(false) + const [showEditListModal, setShowEditListModal] = useState(false) + const [generating, setGenerating] = useState(false) const [newListName, setNewListName] = useState('') const [newListStore, setNewListStore] = useState('') @@ -164,6 +166,33 @@ export default function ShoppingPage() { } } + async function handleGenerateMagicList() { + setGenerating(true) + setError(null) + try { + const newList = await generateMagicList() + void loadLists() + setActiveList(newList) + setView('detail') + } catch { + setError('Erreur lors de la génération') + } finally { + setGenerating(false) + } + } + + async function handleDeleteActiveList() { + if (!activeList) return + try { + await deleteList(activeList.id) + setView('lists') + setActiveList(null) + void loadLists() + } catch { + setError('Erreur lors de la suppression') + } + } + // ── Vue mode magasin ────────────────────────────────────────────────────── if (view === 'store' && activeList) { const unchecked = activeList.items.filter(i => !i.is_checked) @@ -250,6 +279,22 @@ export default function ShoppingPage() { {activeList.checked_count}/{activeList.item_count} cochés + + +
+ + + + )}
) } @@ -338,8 +452,34 @@ export default function ShoppingPage() { // ── Vue liste des listes ─────────────────────────────────────────────────── return (
-
+

Courses

+
{error && (