ListOverlay: don't loop through all items if we just want 2

`map` does not short-circuit
This commit is contained in:
infinite-persistence 2022-03-12 09:27:41 +08:00 committed by Thomas Zarebczan
parent 5b2c901496
commit 2e3f9f94ce

View file

@ -25,20 +25,17 @@ function CollectionPreviewOverlay(props: Props) {
}, [collectionId, collectionItemUrls, fetchCollectionItems]);
if (collectionItemUrls && collectionItemUrls.length > 0) {
const displayed = collectionItemUrls.slice(0, 2);
return (
<div className="collection-preview__overlay-thumbs">
<div className="collection-preview__overlay-side" />
<div className="collection-preview__overlay-grid">
{collectionItemUrls &&
collectionItemUrls.map((item, index) => {
if (index < 2) {
return (
<div className="collection-preview__overlay-grid-items" key={item}>
<FileThumbnail uri={item} />
</div>
);
}
})}
{displayed.map((uri) => (
<div className="collection-preview__overlay-grid-items" key={uri}>
<FileThumbnail uri={uri} />
</div>
))}
</div>
</div>
);