Skip to content

Commit

Permalink
feat: add fullscreen option to overview nft page
Browse files Browse the repository at this point in the history
  • Loading branch information
meness committed Mar 28, 2024
1 parent 9ff6608 commit fb37f20
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 30 deletions.
37 changes: 22 additions & 15 deletions src/app/listing/@nft/(.)nft/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLImageElement>();

const handleClose = () => {
back();
Expand All @@ -32,20 +33,26 @@ const NFTModal = () => {
<Skeleton className="col-span-12 h-[300px] rounded-[var(--nextui-radius-large)] sm:col-span-4" />
)}
{!isPendingNFT && nft && (
<Card className="col-span-12 h-[300px] sm:col-span-4">
<CardHeader className="absolute top-1 z-10 flex-col !items-start">
<p className="text-tiny font-bold uppercase text-white/60">{nft.name}</p>
</CardHeader>
<Image
src={replaceIPFSProtocol(nft.image)}
removeWrapper
alt="NFT"
className="z-0 h-full w-full object-cover"
/>
<CardFooter className="absolute bottom-0 z-10 justify-between border-t-1 border-zinc-100/50 bg-white/30">
{nft.description}
</CardFooter>
</Card>
<button
type="button"
aria-label="See this NFT in the fullscreen mode"
onClick={handleFullscreen}>
<Card className="col-span-12 h-[300px] hover:scale-[1.01] active:scale-100 sm:col-span-4">
<CardHeader className="absolute top-1 z-10 flex-col !items-start">
<p className="text-tiny font-bold uppercase text-white/60">{nft.name}</p>
</CardHeader>
<Image
src={replaceIPFSProtocol(nft.image)}
removeWrapper
alt="NFT"
className="z-0 h-full w-full object-cover"
ref={fullscreenRef}
/>
<CardFooter className="absolute bottom-0 z-10 justify-between border-t-1 border-zinc-100/50 bg-white/30">
{nft.description}
</CardFooter>
</Card>
</button>
)}
</ModalBody>
<ModalFooter>
Expand Down
37 changes: 22 additions & 15 deletions src/app/listing/nft/[id]/_components/nft-card.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLImageElement>();

const handleCancelClick = () => {
push(routeConst.listing);
Expand All @@ -28,20 +29,26 @@ export const NFTCard = () => {
<Skeleton className="col-span-12 h-[300px] rounded-[var(--nextui-radius-large)] sm:col-span-4" />
)}
{!isPendingNFT && nft && (
<Card className="col-span-12 h-[300px] sm:col-span-4">
<CardHeader className="absolute top-1 z-10 flex-col !items-start">
<p className="text-tiny font-bold uppercase text-white/60">{nft.name}</p>
</CardHeader>
<Image
src={replaceIPFSProtocol(nft.image)}
removeWrapper
alt="NFT"
className="z-0 h-full w-full object-cover"
/>
<CardFooter className="absolute bottom-0 z-10 justify-between border-t-1 border-zinc-100/50 bg-white/30">
{nft.description}
</CardFooter>
</Card>
<button
type="button"
aria-label="See this NFT in the fullscreen mode"
onClick={handleFullscreen}>
<Card className="col-span-12 h-[300px] hover:scale-[1.01] active:scale-100 sm:col-span-4">
<CardHeader className="absolute top-1 z-10 flex-col !items-start">
<p className="text-tiny font-bold uppercase text-white/60">{nft.name}</p>
</CardHeader>
<Image
src={replaceIPFSProtocol(nft.image)}
removeWrapper
alt="NFT"
className="z-0 h-full w-full object-cover"
ref={fullscreenRef}
/>
<CardFooter className="absolute bottom-0 z-10 justify-between border-t-1 border-zinc-100/50 bg-white/30">
{nft.description}
</CardFooter>
</Card>
</button>
)}
</CardBody>
<CardFooter>
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './use-fullscreen.hook';
export * from './use-listing.hook';
export * from './use-metadata.hook';
export * from './use-mint.hook';
Expand Down
31 changes: 31 additions & 0 deletions src/hooks/use-fullscreen.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useEffect, useRef, useState } from 'react';
import toast from 'react-hot-toast';

export const useFullscreen = <RefType extends HTMLElement>() => {
const [isInFullscreenMode, setIsInFullscreenMode] = useState(false);
const fullscreenRef = useRef<RefType>(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 };
};

0 comments on commit fb37f20

Please sign in to comment.