Pure logica (splitsen, chips, filter, labels), useSwipeRow en usePackageFilter, ContactPreselect voor het formulier, kaarten in stijl B en tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2.2 KiB
2.2 KiB
Business Logic Model — packages-block (U3)
Data flow
sequenceDiagram
box rgba(99,179,237,0.4) Browser
participant V as Visitor
participant PS as PackagesSection
participant HK as usePackageFilter
end
box rgba(154,230,180,0.4) CMS API
participant A as offerings
end
PS->>A: GET offerings
A-->>PS: package array
PS->>HK: split and derive chips
HK-->>PS: cards, chips, banner
V->>PS: choose a chip
PS->>HK: set active chip
HK-->>PS: filtered cards
V->>PS: click Kies button
PS->>PS: set preselect and scroll to contact
Text alternative: the section loads the offerings, the filter hook splits cards and banner and derives chips, a chip choice filters the cards, and a Kies button sets the contact preselect and scrolls.
Pure functions (unit-testable, src/shared/packages/)
splitPackages(packages, bannerSlugs) -> { cards, banners }deriveChips(cards, threshold) -> Chip[] | null(null = no chips)filterCards(cards, activeId) -> PackageCardData[]resultLabel(count, hasBanner) -> string("1 pakket ...", "3 pakketten ...")initialIndex(visible) -> number(index of the featured card, else 0)activeIndexFromScroll(scrollLeft, itemWidths|itemOffsets, viewportWidth) -> number(nearest snap position)
Hooks
usePackageFilter(packages, settings): stateactiveId; returns{ cards, banners, chips, activeId, setActive, visible, label }; resetsactiveIdtoallwhen the chosen category disappears.useSwipeRow(itemCount, initialIndex): returns{ ref, activeIndex, scrollToIndex }; on mount and whenitemCount/filter key changes scrolls toinitialIndex(instant); listens toscroll(throttled byrequestAnimationFrame) to updateactiveIndex; usesscrollTo({behavior})withsmoothunless reduced motion.useContactPreselect(context from U3, consumed by U4):{ subject, key, select(subject) }.
Error handling
- API error: error state with retry (
refetch); loading: skeletons; empty list: info text. - Unknown/absent
category: package only under "Alles". bannerSlugscontaining an unknown slug: fallback banner from settings.- No
ResizeObserver/IntersectionObserverrequired (scroll event + offsets); jsdom-safe.