Skip to content

Commit b19ab00

Browse files
committed
fix(thumbnails): refactor code and update to latest layout.xml changes
fixes duplicated presentation/screenshare thumbnails in some cases
1 parent 412f6b2 commit b19ab00

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

src/components/thumbnails/index.js

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,46 +83,70 @@ const Thumbnails = ({
8383
const sorted = merged.sort((a, b) => a.timestamp - b.timestamp);
8484

8585
const addThumbsForSwap = sorted.map((item, index, arr) => {
86+
// If the item is a standard thumbnail (not a layout event), preserve it.
87+
if (!item.hasOwnProperty('showScreenshare')) {
88+
return item;
89+
}
90+
8691
const previousItem = arr[index - 1];
8792
const nextItem = arr[index + 1];
88-
if (item.hasOwnProperty('showScreenshare')) {
89-
if (!item.showScreenshare) {
90-
const previousThumbs = arr.slice(0, index)
91-
const Thumbnail = previousThumbs.find((t) => t.src && t.src !== 'screenshare');
92-
// don't add if the src is the same as before
93-
if (Thumbnail?.src === previousItem?.src) {
94-
return null;
95-
} else {
96-
return {
97-
...item,
98-
src: Thumbnail?.src ?? '',
99-
alt: Thumbnail?.alt ?? '',
100-
};
101-
}
102-
} else if (
103-
item.showScreenshare
104-
&& (nextItem && nextItem.src !== 'screenshare')
105-
&& (previousItem && previousItem.src !== 'screenshare')
93+
94+
// Handle logic when screenshare is inactive (restore presentation)
95+
if (!item.showScreenshare) {
96+
// Prevent duplicate consecutive 'restore' actions
97+
if (
98+
previousItem?.hasOwnProperty('showScreenshare')
99+
&& !previousItem.showScreenshare
106100
) {
101+
return null;
102+
}
103+
104+
const previousThumbs = arr.slice(0, index);
105+
const restoredSlide = previousThumbs.find((t) => t.src && t.src !== 'screenshare');
106+
107+
// Only add if the restored slide is different from the immediate previous item
108+
if (restoredSlide?.src && restoredSlide?.src !== previousItem?.src) {
107109
return {
108110
...item,
109-
src: 'screenshare',
110-
alt: 'screenshare',
111-
}
111+
src: restoredSlide.src,
112+
alt: restoredSlide.alt ?? '',
113+
};
112114
}
113115
return null;
114116
}
115-
return item;
116-
}).filter((item) => item !== null);
117117

118-
const reworkIds = addThumbsForSwap.map((item, index) => {
119-
return {
120-
...item,
121-
id: index + 1,
118+
// Handle logic when screenshare is active
119+
if (item.showScreenshare) {
120+
// Prevent duplicate consecutive 'screenshare' actions
121+
if (
122+
previousItem?.hasOwnProperty('showScreenshare')
123+
&& previousItem.showScreenshare
124+
) {
125+
return null;
126+
}
127+
128+
// Ensure strictly valid boundaries (must have valid next/prev items)
129+
const hasValidNeighbors =
130+
(nextItem && nextItem.src !== 'screenshare') &&
131+
(previousItem && previousItem.src !== 'screenshare');
132+
133+
if (hasValidNeighbors) {
134+
return {
135+
...item,
136+
src: 'screenshare',
137+
alt: 'screenshare',
138+
};
139+
}
122140
}
123-
});
124141

125-
return reworkIds;
142+
return null;
143+
}).filter((item) => item !== null);
144+
145+
// Re-index all items sequentially
146+
return addThumbsForSwap.map((item, index) => ({
147+
...item,
148+
id: index + 1,
149+
}));
126150
}, []);
127151

128152
const currentIndex = useCurrentIndex(items);

0 commit comments

Comments
 (0)