This commit is contained in:
Your Name committed 2026-07-12 03:17:30 -04:00
1 parent 9aea635e64
commit c2fc97844f
2 files changed
+8

No files matched your search

@@ -11,18 +11,22 @@ interface ProductImageGalleryProps {
export default function ProductImageGallery({ images, fallback, alt = 'Product Image', badgeText }: ProductImageGalleryProps) { export default function ProductImageGallery({ images, fallback, alt = 'Product Image', badgeText }: ProductImageGalleryProps) {
const [currentIndex, setCurrentIndex] = useState(0) const [currentIndex, setCurrentIndex] = useState(0)
const scrollRef = useRef<HTMLDivElement>(null) const scrollRef = useRef<HTMLDivElement>(null)
const isScrollingRef = useRef(false)
const handleThumbnailClick = (idx: number) => { const handleThumbnailClick = (idx: number) => {
setCurrentIndex(idx) setCurrentIndex(idx)
if (scrollRef.current) { if (scrollRef.current) {
const child = scrollRef.current.children[idx] as HTMLElement const child = scrollRef.current.children[idx] as HTMLElement
if (child) { if (child) {
isScrollingRef.current = true
scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' }) scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
setTimeout(() => { isScrollingRef.current = false }, 600)
} }
} }
} }
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => { const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
if (isScrollingRef.current) return
const container = e.currentTarget const container = e.currentTarget
const scrollLeft = container.scrollLeft const scrollLeft = container.scrollLeft
const width = container.clientWidth const width = container.clientWidth
@@ -12,18 +12,22 @@ interface Props {
export default function ProductGallery({ productName, categoryName, images }: Props) { export default function ProductGallery({ productName, categoryName, images }: Props) {
const [activeIndex, setActiveIndex] = useState(0) const [activeIndex, setActiveIndex] = useState(0)
const scrollRef = useRef<HTMLDivElement>(null) const scrollRef = useRef<HTMLDivElement>(null)
const isScrollingRef = useRef(false)
const handleThumbnailClick = (idx: number) => { const handleThumbnailClick = (idx: number) => {
setActiveIndex(idx) setActiveIndex(idx)
if (scrollRef.current) { if (scrollRef.current) {
const child = scrollRef.current.children[idx] as HTMLElement const child = scrollRef.current.children[idx] as HTMLElement
if (child) { if (child) {
isScrollingRef.current = true
scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' }) scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
setTimeout(() => { isScrollingRef.current = false }, 600)
} }
} }
} }
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => { const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
if (isScrollingRef.current) return
const container = e.currentTarget const container = e.currentTarget
const scrollLeft = container.scrollLeft const scrollLeft = container.scrollLeft
const width = container.clientWidth const width = container.clientWidth