From 34d31a289e4e69099aae64b8aca67bee2062bf7e Mon Sep 17 00:00:00 2001 From: isstuev Date: Sun, 10 Sep 2023 23:44:13 -0300 Subject: [PATCH] refactor --- ui/shared/nft/NftHtmlFullscreen.tsx | 25 +++++++++++++++++ ui/shared/nft/NftImageFullscreen.tsx | 22 +++++++++++++++ ui/shared/nft/NftMedia.tsx | 41 +++++++++++++++++++++++----- ui/shared/nft/NftVideoFullscreen.tsx | 26 ++++++++++++++++++ 4 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 ui/shared/nft/NftHtmlFullscreen.tsx create mode 100644 ui/shared/nft/NftImageFullscreen.tsx create mode 100644 ui/shared/nft/NftVideoFullscreen.tsx diff --git a/ui/shared/nft/NftHtmlFullscreen.tsx b/ui/shared/nft/NftHtmlFullscreen.tsx new file mode 100644 index 0000000000..0e28fab523 --- /dev/null +++ b/ui/shared/nft/NftHtmlFullscreen.tsx @@ -0,0 +1,25 @@ +import { chakra } from '@chakra-ui/react'; +import React from 'react'; + +import NftMediaFullscreenModal from './NftMediaFullscreenModal'; + +interface Props { + src: string; + isOpen: boolean; + onClose: () => void; +} + +const NftHtmlWithFullscreen = ({ src, isOpen, onClose }: Props) => { + return ( + + + + ); +}; + +export default NftHtmlWithFullscreen; diff --git a/ui/shared/nft/NftImageFullscreen.tsx b/ui/shared/nft/NftImageFullscreen.tsx new file mode 100644 index 0000000000..04fad72270 --- /dev/null +++ b/ui/shared/nft/NftImageFullscreen.tsx @@ -0,0 +1,22 @@ +import { + Image, +} from '@chakra-ui/react'; +import React from 'react'; + +import NftMediaFullscreenModal from './NftMediaFullscreenModal'; + +interface Props { + src: string; + isOpen: boolean; + onClose: () => void; +} + +const NftImageWithFullscreen = ({ src, isOpen, onClose }: Props) => { + return ( + + Token instance image + + ); +}; + +export default NftImageWithFullscreen; diff --git a/ui/shared/nft/NftMedia.tsx b/ui/shared/nft/NftMedia.tsx index 48ea6ca360..d9139abf6c 100644 --- a/ui/shared/nft/NftMedia.tsx +++ b/ui/shared/nft/NftMedia.tsx @@ -1,4 +1,4 @@ -import { AspectRatio, chakra, Skeleton } from '@chakra-ui/react'; +import { AspectRatio, chakra, Skeleton, useDisclosure } from '@chakra-ui/react'; import React from 'react'; import { useInView } from 'react-intersection-observer'; @@ -9,11 +9,11 @@ import useFetch from 'lib/hooks/useFetch'; import NftFallback from './NftFallback'; import NftHtml from './NftHtml'; -import NftHtmlWithFullscreen from './NftHtmlWithFullscreen'; +import NftHtmlFullscreen from './NftHtmlFullscreen'; import NftImage from './NftImage'; -import NftImageWithFullscreen from './NftImageWithFullscreen'; +import NftImageFullscreen from './NftImageFullscreen'; import NftVideo from './NftVideo'; -import NftVideoWithFullscreen from './NftVideoWithFullscreen'; +import NftVideoFullscreen from './NftVideoFullscreen'; import type { MediaType } from './utils'; import { getPreliminaryMediaType, mediaStyleProps } from './utils'; @@ -76,6 +76,8 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => { setIsLoadingError(true); }, []); + const { isOpen, onOpen, onClose } = useDisclosure(); + const content = (() => { if (!url || isLoadingError) { const styleProps = withFullscreen ? {} : mediaStyleProps; @@ -86,15 +88,39 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => { src: url, onLoad: handleMediaLoaded, onError: handleMediaLoadError, + ...(withFullscreen ? { onClick: onOpen } : {}), + }; + + switch (type) { + case 'video': + return ; + case 'html': + return ; + case 'image': + return ; + default: + return null; + } + })(); + + const modal = (() => { + if (!url || !withFullscreen) { + return null; + } + + const props = { + src: url, + isOpen, + onClose, }; switch (type) { case 'video': - return withFullscreen ? : ; + return ; case 'html': - return withFullscreen ? : ; + return ; case 'image': - return withFullscreen ? : ; + return ; default: return null; } @@ -117,6 +143,7 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => { > <> { content } + { modal } { isMediaLoading && } diff --git a/ui/shared/nft/NftVideoFullscreen.tsx b/ui/shared/nft/NftVideoFullscreen.tsx new file mode 100644 index 0000000000..dc1685c26b --- /dev/null +++ b/ui/shared/nft/NftVideoFullscreen.tsx @@ -0,0 +1,26 @@ +import { chakra } from '@chakra-ui/react'; +import React from 'react'; + +import NftMediaFullscreenModal from './NftMediaFullscreenModal'; +import { videoPlayProps } from './utils'; + +interface Props { + src: string; + isOpen: boolean; + onClose: () => void; +} + +const NftVideoWithFullscreen = ({ src, isOpen, onClose }: Props) => { + return ( + + + + ); +}; + +export default NftVideoWithFullscreen;