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: decreasing timer to be able to scroll down the category #654

Closed
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
4 changes: 1 addition & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"title": "VTEX Search Result",
"description": "A search result wrapper component",
"mustUpdateAt": "2019-04-25",
"registries": [
"smartcheckout"
],
"registries": ["smartcheckout"],
"scripts": {
"postreleasy": "vtex publish --verbose"
},
Expand Down
13 changes: 4 additions & 9 deletions react/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Fragment, useEffect } from 'react'
import { ProductList as ProductListStructuredData } from 'vtex.structured-data'

import GalleryLayout from './GalleryLayout'
import type { GalleryLayoutProps, Slots } from './GalleryLayout'
import GalleryLayout from './GalleryLayout'
import type { GalleryProps as GalleryLegacyProps } from './GalleryLegacy'
import GalleryLegacy from './GalleryLegacy'

Expand All @@ -28,10 +28,9 @@ const Gallery: React.FC<

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

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

if (elementToScrollTo) {
Expand All @@ -47,22 +46,18 @@ const Gallery: React.FC<
block: 'center',
inline: 'nearest',
})

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

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

recursiveScroll()
}, 1000)
}, 50)

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