Commit 14466dc
Refactor: eliminate code duplication and extract shared utilities (#13)
* Extract extractBasePath and getPathWithoutPrefix to shared utility
Consolidate 10 duplicate copies of extractBasePath and 2 copies of
getPathWithoutPrefix into a single shared module at src/lib/utils/path.ts.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Extract actionResult and withFallback helpers for server actions
Replace 16 identical try/catch blocks across 7 data files with two
shared helpers: actionResult (for mutation results) and withFallback
(for fetch-or-default queries).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Extract product listing logic into shared hook, layout, and utility
- buildProductQueryParams: shared filter-to-query-params conversion
- useProductListing: shared state, pagination, infinite scroll, filter fetching
- ProductListingLayout: shared filter sidebar, skeleton, empty state, load-more UI
ProductsContent shrinks from 410 to 62 lines, CategoryProductsContent
from 373 to 39 lines.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Remove dead internal fetch and useEffect anti-pattern from ProductFilters
- Remove unused internal filter fetching state/effect (~30 lines dead code)
- Remove useStore and getProductFilters imports (no longer needed)
- Make filtersData and loading required props
- Replace useEffect-based onFilterChange with direct calls via updateFilters helper
- Eliminates an unnecessary render cycle on every filter change
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Extract mutateCart helper in CartContext
Replace 3 structurally identical cart mutation callbacks (addItem,
updateItem, removeItem) with a shared mutateCart helper that handles
the setUpdating/result.success/router.refresh pattern.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Extract toUser mapper in AuthContext
Replace 3 identical user-object constructions in refreshUser, login,
and register with a shared toUser helper function.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Centralize cookie helpers and break up StoreContext useEffect
- Extract setStoreCookies helper to src/lib/utils/cookies.ts,
replacing duplicated document.cookie calls with magic numbers
- Extract resolveCountryAndCurrency as a pure function from the
68-line useEffect in StoreContext, improving readability
- Add explicit eslint-disable comment for intentionally excluded
pathname dependency
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Standardize context conventions and minor cleanups
- Standardize CheckoutContext to use undefined (matching Cart, Auth,
Store contexts) instead of null
- Remove unnecessary fragment wrapper in CountrySwitcher
- Remove unused currentCountry variable in CountrySwitcher
- Merge two redundant guard blocks in account layout into one
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Extract shared address types and utilities to eliminate duplication
Consolidate AddressFormData, emptyAddress, addressToFormData, formDataToAddress,
and addressesMatch from 4 files into src/lib/utils/address.ts, removing ~250
lines of duplicated code.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Extract AddressFormFields and AddressEditModal shared components
Replace 4 copies of address form fields (AddressStep, AddressSelector,
PaymentStep BillingAddressForm, account AddressModal) with a single shared
AddressFormFields component. Extract AddressEditModal to replace duplicated
modal+form+state logic in AddressStep and account addresses page.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix pre-existing TypeScript errors in orders.ts and checkout page
- Add missing `meta` field to orders fallback to match PaginatedResponse type
- Fix type narrowing for updateAddress result by checking `!result.success` first
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Address CodeRabbit review feedback
- Add catch block to mutateCart for unhandled network errors
- Return spread copy from addressToFormData to prevent shared state mutation
- Simplify toUser parameter to use User type directly
- Move billing address reset from useEffect to onChange handler
- Add accessibility attrs to AddressEditModal (role, aria-modal, escape key)
- Fix side effect in ProductFilters state updater
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Address PR #13 review feedback
- Fix race condition in useProductListing with loadIdRef guard for
both loadProducts and loadMore to prevent stale results
- Add .catch handlers to fetchStates in AddressEditModal and
PaymentStep to prevent unhandled promise rejections
- Simplify handleUpdateSavedAddress with early-return guard clauses
- Throw instead of silently returning in handleSaveEditedAddress
- Fix PriceFilter inputs not resetting on clearFilters via key prop
- Add error logging to withFallback for production observability
- Use neutral fallback message in applyCouponCode
- Encode cookie values in setStoreCookies
- Spread emptyAddress to avoid shared mutable reference
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* ADD throw error when no variant selected
* FIX: Checkout steps
* ADD Password preview
* FIX aria and cosmetics changes
* REFACTOR method of implementation svg
* FIX lint
* FIX lint single-line error
* FIX tests for svgr
* FIX coderabbits comments
* FIX older coderabbits comments
* FIX lint
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Filip Cichorek <cichorek.filip@gmail.com>File tree
89 files changed
+4360
-3727
lines changed- src
- app
- [country]/[locale]
- (checkout)
- checkout/[id]
- (storefront)
- account
- addresses
- credit-cards
- gift-cards
- orders
- [id]
- register
- cart
- products
- [slug]
- taxonomies
- t/[...permalink]
- components
- cart
- checkout
- icons
- layout
- products
- search
- contexts
- hooks
- lib
- data
- __tests__
- utils
- types
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
89 files changed
+4360
-3727
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
5 | 20 | | |
6 | 21 | | |
7 | 22 | | |
| |||
0 commit comments