diff --git a/refactor-strategy.md b/refactor-strategy.md index bc6902d..655e57d 100644 --- a/refactor-strategy.md +++ b/refactor-strategy.md @@ -32,8 +32,10 @@ Outcome: Feature modules call cohesive services; logic for mapping/normalization ### Phase 3 — Composables (UI-Facing Logic) - [x] Add `src/composables/useAuth.js` (user ref, ensureAuth) -- [ ] Add `src/composables/useMeals.js` (fetch and mutate meals) -- [ ] Refactor pages to use composables and ` \ No newline at end of file diff --git a/src/components/shopping/MyShoppingPage.vue b/src/components/shopping/MyShoppingPage.vue index 6bcc1af..f0aab4a 100644 --- a/src/components/shopping/MyShoppingPage.vue +++ b/src/components/shopping/MyShoppingPage.vue @@ -35,51 +35,47 @@ - \ No newline at end of file diff --git a/src/components/shopping/PurchasedShoppingListPage.vue b/src/components/shopping/PurchasedShoppingListPage.vue index 894d159..9447907 100644 --- a/src/components/shopping/PurchasedShoppingListPage.vue +++ b/src/components/shopping/PurchasedShoppingListPage.vue @@ -29,42 +29,25 @@ - \ No newline at end of file diff --git a/src/composables/useShopping.js b/src/composables/useShopping.js new file mode 100644 index 0000000..7a21358 --- /dev/null +++ b/src/composables/useShopping.js @@ -0,0 +1,27 @@ +import { + getCurrentShoppingList, + getShoppingList, + purchaseShoppingList, + requestMeal, + unrequestMeal, + getMyShoppingList, + saveMyShoppingList, +} from '@/api/shopping' +import { groupsToItems } from '@/components/shopping/shopping.js' + +export function useShopping() { + return { + getCurrentShoppingList, + getShoppingList, + purchaseShoppingList, + requestMeal, + unrequestMeal, + getMyShoppingList, + saveMyShoppingList, + async purchaseFromGroups(groups) { + const items = groupsToItems(groups) + if (!items?.length) return null + return purchaseShoppingList(items) + }, + } +}