Commit f8399fd0 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: enforce uniform asset height (#5181)

* fix: show loading assets at uniform height

* fix: enforce the uniform asset height

* fix: memoize assets

* fix: be more lenient with uniformHeight

* fix: simplify mapping
parent 429ade5b
...@@ -267,9 +267,11 @@ const Image = ({ uniformHeight, setUniformHeight }: ImageProps) => { ...@@ -267,9 +267,11 @@ const Image = ({ uniformHeight, setUniformHeight }: ImageProps) => {
if (uniformHeight === UniformHeights.unset) { if (uniformHeight === UniformHeights.unset) {
setUniformHeight(e.currentTarget.clientHeight) setUniformHeight(e.currentTarget.clientHeight)
} else if (uniformHeight !== UniformHeights.notUniform && e.currentTarget.clientHeight !== uniformHeight) { } else if (uniformHeight !== UniformHeights.notUniform && e.currentTarget.clientHeight !== uniformHeight) {
if (!uniformHeight || Math.abs(uniformHeight - e.currentTarget.clientHeight) > 1) {
setUniformHeight(UniformHeights.notUniform) setUniformHeight(UniformHeights.notUniform)
} }
} }
}
setLoaded(true) setLoaded(true)
}} }}
className={clsx(hovered && !isMobile && styles.cardImageHover, !loaded && styles.loadingBackground)} className={clsx(hovered && !isMobile && styles.cardImageHover, !loaded && styles.loadingBackground)}
...@@ -422,9 +424,11 @@ const Audio = ({ uniformHeight, setUniformHeight, shouldPlay, setCurrentTokenPla ...@@ -422,9 +424,11 @@ const Audio = ({ uniformHeight, setUniformHeight, shouldPlay, setCurrentTokenPla
uniformHeight !== UniformHeights.notUniform && uniformHeight !== UniformHeights.notUniform &&
e.currentTarget.clientHeight !== uniformHeight e.currentTarget.clientHeight !== uniformHeight
) { ) {
if (!uniformHeight || Math.abs(uniformHeight - e.currentTarget.clientHeight) > 1) {
setUniformHeight(UniformHeights.notUniform) setUniformHeight(UniformHeights.notUniform)
} }
} }
}
setImageLoaded(true) setImageLoaded(true)
}} }}
className={clsx(hovered && !isMobile && styles.cardImageHover, !imageLoaded && styles.loadingBackground)} className={clsx(hovered && !isMobile && styles.cardImageHover, !imageLoaded && styles.loadingBackground)}
......
...@@ -5,10 +5,10 @@ import { Box } from '../../components/Box' ...@@ -5,10 +5,10 @@ import { Box } from '../../components/Box'
import { Row } from '../Flex' import { Row } from '../Flex'
import * as styles from './CollectionAssetLoading.css' import * as styles from './CollectionAssetLoading.css'
export const CollectionAssetLoading = () => { export const CollectionAssetLoading = ({ height }: { height?: number }) => {
return ( return (
<Box as="div" className={styles.collectionAssetLoading}> <Box as="div" className={styles.collectionAssetLoading}>
<Box as="div" position="relative" width="full"> <Box as="div" position="relative" width="full" style={{ height }}>
<Box as="div" className={styles.collectionAssetsImageLoading} /> <Box as="div" className={styles.collectionAssetsImageLoading} />
<Box as="img" width="full" opacity="0" src={SizingImage} draggable={false} /> <Box as="img" width="full" opacity="0" src={SizingImage} draggable={false} />
</Box> </Box>
......
...@@ -166,17 +166,17 @@ export const LoadingButton = styled.div` ...@@ -166,17 +166,17 @@ export const LoadingButton = styled.div`
background-size: 400%; background-size: 400%;
` `
const loadingAssets = ( const loadingAssets = (height?: number) => (
<> <>
{Array.from(Array(ASSET_PAGE_SIZE), (_, index) => ( {Array.from(Array(ASSET_PAGE_SIZE), (_, index) => (
<CollectionAssetLoading key={index} /> <CollectionAssetLoading key={index} height={height} />
))} ))}
</> </>
) )
export const CollectionNftsLoading = () => ( export const CollectionNftsLoading = () => (
<Box width="full" className={styles.assetList}> <Box width="full" className={styles.assetList}>
{loadingAssets} {loadingAssets()}
</Box> </Box>
) )
...@@ -323,10 +323,9 @@ export const CollectionNfts = ({ contractAddress, collectionStats, rarityVerifie ...@@ -323,10 +323,9 @@ export const CollectionNfts = ({ contractAddress, collectionStats, rarityVerifie
} }
}, [contractAddress]) }, [contractAddress])
const Nfts = const assets = useMemo(() => {
collectionNfts && if (!collectionNfts) return null
collectionNfts.map((asset) => return collectionNfts.map((asset) => (
asset ? (
<CollectionAsset <CollectionAsset
key={asset.address + asset.tokenId} key={asset.address + asset.tokenId}
asset={asset} asset={asset}
...@@ -337,8 +336,8 @@ export const CollectionNfts = ({ contractAddress, collectionStats, rarityVerifie ...@@ -337,8 +336,8 @@ export const CollectionNfts = ({ contractAddress, collectionStats, rarityVerifie
setCurrentTokenPlayingMedia={setCurrentTokenPlayingMedia} setCurrentTokenPlayingMedia={setCurrentTokenPlayingMedia}
rarityVerified={rarityVerified} rarityVerified={rarityVerified}
/> />
) : null ))
) }, [collectionNfts, currentTokenPlayingMedia, isMobile, rarityVerified, uniformHeight])
const hasNfts = collectionNfts && collectionNfts.length > 0 const hasNfts = collectionNfts && collectionNfts.length > 0
const hasErc1155s = hasNfts && collectionNfts[0] && collectionNfts[0].tokenType === TokenType.ERC1155 const hasErc1155s = hasNfts && collectionNfts[0] && collectionNfts[0].tokenType === TokenType.ERC1155
...@@ -509,13 +508,13 @@ export const CollectionNfts = ({ contractAddress, collectionStats, rarityVerifie ...@@ -509,13 +508,13 @@ export const CollectionNfts = ({ contractAddress, collectionStats, rarityVerifie
<InfiniteScroll <InfiniteScroll
next={() => loadNext(ASSET_PAGE_SIZE)} next={() => loadNext(ASSET_PAGE_SIZE)}
hasMore={hasNext} hasMore={hasNext}
loader={hasNext && hasNfts ? loadingAssets : null} loader={hasNext && hasNfts ? loadingAssets(uniformHeight) : null}
dataLength={collectionNfts?.length ?? 0} dataLength={collectionNfts?.length ?? 0}
style={{ overflow: 'unset' }} style={{ overflow: 'unset' }}
className={hasNfts || isLoadingNext ? styles.assetList : undefined} className={hasNfts || isLoadingNext ? styles.assetList : undefined}
> >
{hasNfts ? ( {hasNfts ? (
Nfts assets
) : collectionNfts?.length === 0 ? ( ) : collectionNfts?.length === 0 ? (
<Center width="full" color="textSecondary" textAlign="center" style={{ height: '60vh' }}> <Center width="full" color="textSecondary" textAlign="center" style={{ height: '60vh' }}>
<EmptyCollectionWrapper> <EmptyCollectionWrapper>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment