Skip to content

Commit

Permalink
PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
noam-heller1 committed Nov 30, 2023
1 parent b3ee31a commit 77c161c
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down

0 comments on commit 77c161c

Please sign in to comment.