Skip to content

Commit

Permalink
Yank 3.127.1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thalytafabrine committed Mar 4, 2024
1 parent fe156a4 commit 9a5231f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 55 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Yank `3.127.1` changes.

## [3.129.6] - 2024-02-23

### Fixed
Expand Down Expand Up @@ -60,7 +63,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Use the advanced setting `fetchSponsoredProductsOnSearch` to determine whether or not to fetch sponsored products.

## [3.127.1] - 2023-10-24
## [3.127.1] - 2023-10-24 [YANKED]

### changed
- Behavior `scrollToElement` added to Gallery component for PLP.
Expand Down
63 changes: 11 additions & 52 deletions react/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment, useEffect } from 'react'
import React, { Fragment } from 'react'
import { ProductList as ProductListStructuredData } from 'vtex.structured-data'

import GalleryLayout from './GalleryLayout'
Expand All @@ -16,58 +16,17 @@ type GalleryLayoutPropsWithSlots = Omit<GalleryLayoutProps, 'slots'> & Slots
const Gallery: React.FC<
GalleryLegacyProps | GalleryLayoutPropsWithSlots
> = props => {
const {
layouts,
lazyItemsRemaining,
products,
showingFacets,
summary,
preferredSKU,
...slots
} = props as GalleryLayoutPropsWithSlots

useEffect(() => {
const lastClickedProductId = localStorage.getItem('lastClickedProductId')
const isMobile = window.innerWidth <= 768

const delayedExecution = setTimeout(() => {
const scrollToElement = (elementId: string, offset: number) => {
const elementToScrollTo = document.getElementById(elementId)

if (elementToScrollTo) {
const rect = elementToScrollTo.getBoundingClientRect()
const isElementVisible =
rect.top >= 0 &&
rect.bottom <=
(window.innerHeight || document.documentElement.clientHeight)

if (!isElementVisible) {
elementToScrollTo.scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'nearest',
})

setTimeout(() => {
scrollToElement(elementId, offset)
}, 500)
}
}
}

const recursiveScroll = () => {
if (lastClickedProductId) {
scrollToElement(lastClickedProductId, isMobile ? -200 : -200)
}
}

recursiveScroll()
}, 1000)

return () => clearTimeout(delayedExecution)
}, [])

if ('layouts' in props && props.layouts.length > 0) {
const {
layouts,
lazyItemsRemaining,
products,
showingFacets,
summary,
preferredSKU,
...slots
} = props as GalleryLayoutPropsWithSlots

return (
<Fragment>
<ProductListStructuredData products={products} />
Expand Down
1 change: 0 additions & 1 deletion react/components/GalleryLayoutItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const GalleryLayoutItem: React.FC<GalleryLayoutItemProps> = ({
position,
list: listName,
})
localStorage.setItem('lastClickedProductId', product.productId)
}, [
product,
push,
Expand Down
1 change: 0 additions & 1 deletion react/components/GalleryLayoutRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const GalleryLayoutRow: React.FC<GalleryLayoutRowProps> = ({
]),
'pa4'
)}
id={product.productId}
>
<GalleryItem
GalleryItemComponent={GalleryItemComponent}
Expand Down

0 comments on commit 9a5231f

Please sign in to comment.