Skip to content

Commit

Permalink
fix scrolltoindex firing on last card dismissal (#5606)
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat authored Apr 9, 2024
1 parent 77ef889 commit 1f4bfa0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/cards/remote-cards/RemoteCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,17 @@ export const RemoteCard: React.FC<RemoteCardProps> = ({ card = {} as TrimmedCard
analyticsV2.track(analyticsV2.event.remoteCardDismissed, {
cardKey: cardKey ?? 'unknown-backend-driven-card',
});

const isLastCard = cards.length === 1;

dismissCard(card.sys.id);
if (carouselRef?.current) {
const currentCardIdx = cards.findIndex(c => c.cardKey === cardKey);
if (currentCardIdx === -1) return;

// check if this is the last card and don't scroll if so
if (isLastCard) return;

carouselRef.current.scrollToIndex({
index: currentCardIdx,
animated: true,
Expand Down

0 comments on commit 1f4bfa0

Please sign in to comment.