From 2cc87e1891208a6b4bc1be887c46545a5cc0e5cc Mon Sep 17 00:00:00 2001 From: jableader Date: Sat, 18 Oct 2025 13:01:18 +1100 Subject: [PATCH] Refactor #5 --- refactor-strategy.md | 8 +- .../shopping/CurrentShoppingListPage.vue | 178 ++++++++---------- src/components/shopping/MyShoppingPage.vue | 76 ++++---- .../shopping/PurchasedShoppingListPage.vue | 45 ++--- src/composables/useShopping.js | 27 +++ 5 files changed, 159 insertions(+), 175 deletions(-) create mode 100644 src/composables/useShopping.js 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) + }, + } +}