diff --git a/src/app/listing/@nft/(.)nft/[id]/page.tsx b/src/app/listing/@nft/(.)nft/[id]/page.tsx index 38af470..e445207 100644 --- a/src/app/listing/@nft/(.)nft/[id]/page.tsx +++ b/src/app/listing/@nft/(.)nft/[id]/page.tsx @@ -8,12 +8,13 @@ import { Skeleton } from '@nextui-org/skeleton'; import 'filepond/dist/filepond.min.css'; import { useParams, useRouter } from 'next/navigation'; import { replaceIPFSProtocol } from '~helpers'; -import { useNFT } from '~hooks'; +import { useFullscreen, useNFT } from '~hooks'; const NFTModal = () => { const { id: nftID } = useParams<{ id: string }>(); const { back } = useRouter(); const { nft, isPending: isPendingNFT } = useNFT(BigInt(nftID)); + const { fullscreenRef, handleFullscreen } = useFullscreen(); const handleClose = () => { back(); @@ -32,20 +33,26 @@ const NFTModal = () => { )} {!isPendingNFT && nft && ( - - -

{nft.name}

-
- NFT - - {nft.description} - -
+ )} diff --git a/src/app/listing/nft/[id]/_components/nft-card.component.tsx b/src/app/listing/nft/[id]/_components/nft-card.component.tsx index c290433..61e75eb 100644 --- a/src/app/listing/nft/[id]/_components/nft-card.component.tsx +++ b/src/app/listing/nft/[id]/_components/nft-card.component.tsx @@ -8,12 +8,13 @@ import 'filepond/dist/filepond.min.css'; import { useParams, useRouter } from 'next/navigation'; import { routeConst } from '~common/consts'; import { replaceIPFSProtocol } from '~helpers'; -import { useNFT } from '~hooks'; +import { useFullscreen, useNFT } from '~hooks'; export const NFTCard = () => { const { push } = useRouter(); const { id: nftID } = useParams<{ id: string }>(); const { nft, isPending: isPendingNFT } = useNFT(BigInt(nftID)); + const { fullscreenRef, handleFullscreen } = useFullscreen(); const handleCancelClick = () => { push(routeConst.listing); @@ -28,20 +29,26 @@ export const NFTCard = () => { )} {!isPendingNFT && nft && ( - - -

{nft.name}

-
- NFT - - {nft.description} - -
+ )} diff --git a/src/hooks/index.ts b/src/hooks/index.ts index dca6a2a..f235d26 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,3 +1,4 @@ +export * from './use-fullscreen.hook'; export * from './use-listing.hook'; export * from './use-metadata.hook'; export * from './use-mint.hook'; diff --git a/src/hooks/use-fullscreen.hook.ts b/src/hooks/use-fullscreen.hook.ts new file mode 100644 index 0000000..0181579 --- /dev/null +++ b/src/hooks/use-fullscreen.hook.ts @@ -0,0 +1,31 @@ +import { useEffect, useRef, useState } from 'react'; +import toast from 'react-hot-toast'; + +export const useFullscreen = () => { + const [isInFullscreenMode, setIsInFullscreenMode] = useState(false); + const fullscreenRef = useRef(null); + + useEffect(() => { + document.addEventListener('fullscreenchange', () => { + if (!document.fullscreenElement) { + setIsInFullscreenMode(false); + } else if (document.fullscreenElement) { + setIsInFullscreenMode(true); + } + }); + }, []); + + const handleFullscreen = () => { + if (document.fullscreenEnabled) { + if (!document.fullscreenElement) { + fullscreenRef.current?.requestFullscreen(); + } else if (document.fullscreenElement) { + document.exitFullscreen(); + } + } else { + toast.error('Fullscreen mode is disabled'); + } + }; + + return { isInFullscreenMode, fullscreenRef, handleFullscreen }; +};