Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AllVariantsCarousel: next / prev show even if only one item; others #99

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/commerce/components/buy/carousel-buy-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const CarouselBuyCard: React.FC<{
<div className={clx}>
<AddToCartWidget
item={cmmc.currentItem}
registerAdd={false}
registerAdd={true}
onQuantityChanged={onQuantityChanged}
variant={cmmc.cartEmpty ? 'primary' : 'outline'}
className={addBtnClx}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ const AllVariantsCarousel: React.FC<MultiFamilySelectorProps> = ({
</CarouselItem>
))}
</CarouselContent>
<CarouselPrevious className='left-1'/>
<CarouselNext className='right-1'/>
{r.current.items.length > 1 && (<>
<CarouselPrevious className='left-1'/>
<CarouselNext className='right-1'/>
</>)}
</Carousel>
)}
<ItemInfo labelClx='!text-base font-medium'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const CartLineItem: React.FC<{
</div>
<div className='flex flex-row items-center justify-between w-full'>
<div className='flex flex-row items-center'>
<AddToCartWidget variant='minimal' item={item} buttonClx='!h-8 md:!h-6' />
<AddToCartWidget variant='minimal' registerAdd={false} item={item} buttonClx='!h-8 md:!h-6' />
{item.quantity > 1 && (<span className='pl-2.5'>{'@' + formatCurrencyValue(item.price)}</span>)}
</div>
<div className='flex flex-row gap-1 items-center justify-end'>
Expand Down
14 changes: 6 additions & 8 deletions packages/commerce/context/commerce-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import {
makeObservable,
observable,
} from 'mobx'
import type { CommerceService, LineItem } from '../types'
import type { CommerceService, LineItem, ObsLineItemRef } from '../types'



interface CommerceUI {
interface CommerceUI extends ObsLineItemRef {
showBuyOptions: (skuPath: string) => void
hideBuyOptions: () => void
get buyOptionsSkuPath(): string | undefined

itemQuantityChanged(item: LineItem, val: number, prevVal: number): void
get activeItem(): LineItem | undefined
itemQuantityChanged(item: LineItem, val: number, prevVal: number): void
}

class CommerceUIStore implements CommerceUI {

static readonly TIMEOUT = 2500
static readonly TIMEOUT = 1500
_buyOptionsSkuPath: string | undefined = undefined
_paused: boolean = false
_activeItem: LineItem | undefined = undefined
Expand All @@ -36,7 +34,7 @@ class CommerceUIStore implements CommerceUI {
buyOptionsSkuPath: computed,
itemQuantityChanged: action,
tick: action,
activeItem: computed
item: computed
})
}

Expand Down Expand Up @@ -92,7 +90,7 @@ class CommerceUIStore implements CommerceUI {
}
}

get activeItem(): LineItem | undefined {
get item(): LineItem | undefined {
return this._activeItem
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/commerce/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ const CommerceProvider: React.FC<PropsWithChildren & {
rootNode: CategoryNode
options?: ServiceOptions
uiSpecs?: Record<string, SelectionUISpecifier>
DEBUG_NO_TICK?: boolean
}> = ({
children,
families,
rootNode,
options,
uiSpecs
uiSpecs,
DEBUG_NO_TICK=false
}) => {

useEffect(() => {
if (DEBUG_NO_TICK) return
const intervalId = setInterval(() => {
(valueRef.current.ui as CommerceUIStore).tick()
}, 250)
return () => {clearInterval(intervalId)}
return () => { clearInterval(intervalId) }
}, [])

// TODO: Inject Promo fixture here from siteDef
Expand Down
1 change: 1 addition & 0 deletions packages/commerce/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './context'
export * from './components'
// Impl-dependent, so leave w impl
export type { StandaloneServiceOptions as ServiceOptions } from './service/impls/standalone/standalone-service'
export {
useSyncSkuParamWithCurrentItem,
Expand Down
1 change: 1 addition & 0 deletions packages/commerce/util/line-item-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LineItemRef implements ObsLineItemRef {
}

get item(): LineItem | undefined { return this._item }

set = (v: LineItem | undefined): void => { this._item = v }
}

Expand Down
Loading