-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from alephium/support-mp4
Support MP4 for NFT
- Loading branch information
Showing
4 changed files
with
91 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 47 additions & 18 deletions
65
packages/extension/src/ui/features/accountNfts/NftThumbnailImage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,58 @@ | ||
import { Flex, Image, Spinner } from "@chakra-ui/react" | ||
import { FC, ImgHTMLAttributes } from "react" | ||
import { FC, ImgHTMLAttributes, useRef } from "react" | ||
|
||
import { NftFallback } from "./NftFallback" | ||
import { isMp4Url } from "./alephium-nft.service" | ||
|
||
type NftThumbnailImage = ImgHTMLAttributes<HTMLImageElement> | ||
|
||
/** Transparently displays an image or palceholder fallback set to square aspect ratio */ | ||
|
||
export const NftThumbnailImage: FC<NftThumbnailImage> = ({ src, ...rest }) => { | ||
const videoRef = useRef<HTMLVideoElement>(null) | ||
if (!src) { | ||
return <NftFallback /> | ||
} | ||
return ( | ||
<Image | ||
src={src} | ||
{...rest} | ||
w="142px" | ||
h="142px" | ||
borderRadius="lg" | ||
position="relative" | ||
fallback={ | ||
<Flex w="142px" h="142px" justifyContent="center" alignItems="center"> | ||
<Spinner /> | ||
</Flex> | ||
} | ||
/> | ||
) | ||
|
||
if (isMp4Url(src)) { | ||
return ( | ||
<video | ||
ref={videoRef} | ||
src={src} | ||
style={{ | ||
width: '142px', | ||
height: '142px', | ||
borderRadius: '8px', | ||
position: 'relative', | ||
objectFit: 'cover', | ||
cursor: 'pointer' | ||
}} | ||
onMouseEnter={() => videoRef.current?.play()} | ||
onMouseLeave={() => { | ||
if (videoRef.current) { | ||
videoRef.current.pause() | ||
videoRef.current.currentTime = 0 | ||
} | ||
}} | ||
loop | ||
muted | ||
playsInline | ||
/> | ||
) | ||
} else { | ||
return ( | ||
<Image | ||
src={src} | ||
{...rest} | ||
w="142px" | ||
h="142px" | ||
borderRadius="lg" | ||
position="relative" | ||
objectFit="cover" | ||
fallback={ | ||
<Flex w="142px" h="142px" justifyContent="center" alignItems="center"> | ||
<Spinner /> | ||
</Flex> | ||
} | ||
/> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters