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

Yank 3.127.1 changes #659

Merged
merged 1 commit into from
Mar 6, 2024
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Yank `3.127.1` changes.

## [3.129.7] - 2024-03-05

### Fixed
Expand Down Expand Up @@ -65,7 +69,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 @@ -8,7 +8,7 @@
import type { PreferredSKU } from '../GalleryLayout'

interface GalleryLayoutItemProps {
GalleryItemComponent: ComponentType<any>

Check warning on line 11 in react/components/GalleryLayoutItem.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
item: Product
displayMode: string
summary: unknown
Expand Down Expand Up @@ -44,7 +44,6 @@
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
Loading