Skip to content

Commit

Permalink
fix thumbnails duplication (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzaacAyelin committed May 28, 2024
1 parent dd8b1d6 commit cc37648
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class NavigationPanel extends React.Component {
style={{ ...thumbnailsStyle }}
>
{items.map(({ thumbnailItem, location, idx }) => {
const highlighted = idx === activeIndex;
const highlighted = idx === activeIndex % items.length;
const itemStyle = {
width: thumbnailSize,
height: thumbnailSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,8 @@ class SlideshowView extends React.Component {
this.props.options.groupSize === 1 &&
!this.props.isScrollLessGallery
) {
const skipToSlide = this.skipFromSlide - this.props.totalItemsCount;

if (nextItem >= this.skipFromSlide) {
nextItem = skipToSlide;
nextItem = utils.inRange(nextItem, this.props.totalItemsCount);
await this.props.actions.scrollToItem(nextItem);
}
}
Expand Down Expand Up @@ -487,15 +485,24 @@ class SlideshowView extends React.Component {
}
};

getFirstIdx(itemIdx) {
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 activeIdx = this.state.activeIndex;
const targetIdx =
activeIdx + (this.getFirstIdx(itemIdx) - this.getFirstIdx(activeIdx));
this.scrollToIndex({
itemIdx,
itemIdx: targetIdx,
scrollDuration,
isRTL: this.props.options.isRTL,
});
Expand Down
7 changes: 5 additions & 2 deletions packages/gallery/src/components/helpers/thumbnailsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function calculateActiveIndexOffset({
export function clearGalleryItems(items: any[], galleryItems: any[]): any[] {

Check warning on line 34 in packages/gallery/src/components/helpers/thumbnailsLogic.ts

View workflow job for this annotation

GitHub Actions / lint (16.13.0)

Unexpected any. Specify a different type

Check warning on line 34 in packages/gallery/src/components/helpers/thumbnailsLogic.ts

View workflow job for this annotation

GitHub Actions / lint (16.13.0)

Unexpected any. Specify a different type
const clear = (list) =>
utils
.uniqueBy(list, 'idx')
.uniqueBy(list, 'id')
.filter((item) => item.idx !== undefined)
.sort((a, b) => a.idx - b.idx);
const clearedGalleryItems = clear(galleryItems);
Expand Down Expand Up @@ -117,6 +117,7 @@ export function getThumbnailsData({
height,
thumbnailSizeWithSpacing,
activeIndex: activeIndexWithOffset,
itemsCount: galleryItems.length,
});

const thumbnailsStyleWithRTLCalc = isRTL
Expand Down Expand Up @@ -201,12 +202,14 @@ function getThumbnailsStyles({
height,
activeIndex,
thumbnailSizeWithSpacing,
itemsCount: numberOfItems,
}: {
horizontalThumbnails: boolean;
width: number;
height: number;
activeIndex: number;
thumbnailSizeWithSpacing: number;
itemsCount: number;
}): CSSProperties {
const baseStyle = {
overflow: 'visible',
Expand All @@ -215,7 +218,7 @@ function getThumbnailsStyles({
};
const size = horizontalThumbnails ? width : height;
const unit = horizontalThumbnails ? 'left' : 'top';
const distance = thumbnailSizeWithSpacing * activeIndex;
const distance = thumbnailSizeWithSpacing * (activeIndex % numberOfItems);
const initialCenter = size / 2 - thumbnailSizeWithSpacing / 2;

return {
Expand Down

0 comments on commit cc37648

Please sign in to comment.