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]); }, [collectionId, collectionItemUrls, fetchCollectionItems]);
if (collectionItemUrls && collectionItemUrls.length > 0) { if (collectionItemUrls && collectionItemUrls.length > 0) {
const displayed = collectionItemUrls.slice(0, 2);
return ( return (
<div className="collection-preview__overlay-thumbs"> <div className="collection-preview__overlay-thumbs">
<div className="collection-preview__overlay-side" /> <div className="collection-preview__overlay-side" />
<div className="collection-preview__overlay-grid"> <div className="collection-preview__overlay-grid">
{collectionItemUrls && {displayed.map((uri) => (
collectionItemUrls.map((item, index) => { <div className="collection-preview__overlay-grid-items" key={uri}>
if (index < 2) { <FileThumbnail uri={uri} />
return ( </div>
<div className="collection-preview__overlay-grid-items" key={item}> ))}
<FileThumbnail uri={item} />
</div>
);
}
})}
</div> </div>
</div> </div>
); );