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 thumbnails duplication #1241

Merged
merged 1 commit into from
May 28, 2024
Merged
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
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 @@ -31,10 +31,10 @@
return activeIndexOffsetMemory;
}

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 @@
height,
thumbnailSizeWithSpacing,
activeIndex: activeIndexWithOffset,
itemsCount: galleryItems.length,
});

const thumbnailsStyleWithRTLCalc = isRTL
Expand Down Expand Up @@ -201,12 +202,14 @@
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 @@
};
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
Loading