From 77c161c685bbec3a033002a768a9a2be1a32dd72 Mon Sep 17 00:00:00 2001 From: noam-heller1 Date: Thu, 30 Nov 2023 12:05:35 +0200 Subject: [PATCH] PR comment --- .../components/gallery/proGallery/slideshowView.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/gallery/src/components/gallery/proGallery/slideshowView.js b/packages/gallery/src/components/gallery/proGallery/slideshowView.js index e78db5158..c62afbf1c 100644 --- a/packages/gallery/src/components/gallery/proGallery/slideshowView.js +++ b/packages/gallery/src/components/gallery/proGallery/slideshowView.js @@ -435,21 +435,17 @@ class SlideshowView extends React.Component { }; getFirstIdx(itemIdx) { - const activeItem = this.props.galleryStructure.galleryItems[itemIdx]; - const activeItemId = activeItem.itemId; - const firstItemInstance = this.props.galleryStructure.galleryItems.find((item) => item.itemId === activeItemId); - return firstItemInstance.idx; + const { galleryItems } = this.props.galleryStructure; + const activeItemId = galleryItems[itemIdx].itemId; + return galleryItems.find((item) => item.itemId === activeItemId).idx; } scrollToThumbnail(itemIdx, scrollDuration) { //not to confuse with this.props.actions.scrollToItem. this is used to replace it only for thumbnail items this.props.actions.eventsListener(GALLERY_CONSTS.events.THUMBNAIL_CLICKED, this.props); - const activeItemFirstIdx = this.getFirstIdx(this.state.activeIndex); - const firstTargetItemIdx = this.getFirstIdx(itemIdx); - const distance = firstTargetItemIdx - activeItemFirstIdx; - const targetIdx = this.state.activeIndex + distance; - + const activeIdx = this.state.activeIndex; + const targetIdx = activeIdx + (this.getFirstIdx(itemIdx) - this.getFirstIdx(activeIdx)); this.scrollToIndex({ itemIdx: targetIdx, scrollDuration }); }