Commit 33f2d497 authored by isstuev's avatar isstuev

refactor

parent b903406f
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 (
<NftMediaFullscreenModal isOpen={ isOpen } onClose={ onClose }>
<chakra.iframe
w="90vw"
h="90vh"
src={ src }
sandbox="allow-scripts"
/>
</NftMediaFullscreenModal>
);
};
export default NftHtmlWithFullscreen;
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 (
<NftMediaFullscreenModal isOpen={ isOpen } onClose={ onClose }>
<Image src={ src } alt="Token instance image" maxH="90vh" maxW="90vw"/>
</NftMediaFullscreenModal>
);
};
export default NftImageWithFullscreen;
import { AspectRatio, chakra, Skeleton } from '@chakra-ui/react'; import { AspectRatio, chakra, Skeleton, useDisclosure } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import { useInView } from 'react-intersection-observer'; import { useInView } from 'react-intersection-observer';
import NftFallback from './NftFallback'; import NftFallback from './NftFallback';
import NftHtml from './NftHtml'; import NftHtml from './NftHtml';
import NftHtmlWithFullscreen from './NftHtmlWithFullscreen'; import NftHtmlFullscreen from './NftHtmlFullscreen';
import NftImage from './NftImage'; import NftImage from './NftImage';
import NftImageWithFullscreen from './NftImageWithFullscreen'; import NftImageFullscreen from './NftImageFullscreen';
import NftVideo from './NftVideo'; import NftVideo from './NftVideo';
import NftVideoWithFullscreen from './NftVideoWithFullscreen'; import NftVideoFullscreen from './NftVideoFullscreen';
import useNftMediaType from './useNftMediaType'; import useNftMediaType from './useNftMediaType';
import { mediaStyleProps } from './utils'; import { mediaStyleProps } from './utils';
...@@ -36,6 +36,8 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => { ...@@ -36,6 +36,8 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => {
setIsLoadingError(true); setIsLoadingError(true);
}, []); }, []);
const { isOpen, onOpen, onClose } = useDisclosure();
const content = (() => { const content = (() => {
if (!url || isLoadingError) { if (!url || isLoadingError) {
const styleProps = withFullscreen ? {} : mediaStyleProps; const styleProps = withFullscreen ? {} : mediaStyleProps;
...@@ -46,15 +48,39 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => { ...@@ -46,15 +48,39 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => {
src: url, src: url,
onLoad: handleMediaLoaded, onLoad: handleMediaLoaded,
onError: handleMediaLoadError, onError: handleMediaLoadError,
...(withFullscreen ? { onClick: onOpen } : {}),
};
switch (type) {
case 'video':
return <NftVideo { ...props }/>;
case 'html':
return <NftHtml { ...props }/>;
case 'image':
return <NftImage { ...props }/>;
default:
return null;
}
})();
const modal = (() => {
if (!url || !withFullscreen) {
return null;
}
const props = {
src: url,
isOpen,
onClose,
}; };
switch (type) { switch (type) {
case 'video': case 'video':
return withFullscreen ? <NftVideoWithFullscreen { ...props }/> : <NftVideo { ...props }/>; return <NftVideoFullscreen { ...props }/>;
case 'html': case 'html':
return withFullscreen ? <NftHtmlWithFullscreen { ...props }/> : <NftHtml { ...props }/>; return <NftHtmlFullscreen { ...props }/>;
case 'image': case 'image':
return withFullscreen ? <NftImageWithFullscreen { ...props }/> : <NftImage { ...props }/>; return <NftImageFullscreen { ...props }/>;
default: default:
return null; return null;
} }
...@@ -77,6 +103,7 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => { ...@@ -77,6 +103,7 @@ const NftMedia = ({ url, className, isLoading, withFullscreen }: Props) => {
> >
<> <>
{ content } { content }
{ modal }
{ isMediaLoading && <Skeleton position="absolute" left={ 0 } top={ 0 } w="100%" h="100%" zIndex="1"/> } { isMediaLoading && <Skeleton position="absolute" left={ 0 } top={ 0 } w="100%" h="100%" zIndex="1"/> }
</> </>
</AspectRatio> </AspectRatio>
......
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 (
<NftMediaFullscreenModal isOpen={ isOpen } onClose={ onClose }>
<chakra.video
{ ...videoPlayProps }
src={ src }
maxH="90vh"
maxW="90vw"
/>
</NftMediaFullscreenModal>
);
};
export default NftVideoWithFullscreen;
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