From 0a7ed0146516b4ab000a198ba64321bacb797b81 Mon Sep 17 00:00:00 2001 From: Suraj Mahto Date: Wed, 30 Oct 2024 23:37:50 +0530 Subject: [PATCH] feat : modified url name for nft and collection --- src/app/collection/[id]/page.js | 34 +++++++++++----------- src/app/nfts/[id]/page.js | 50 +++++++++++++++++++++------------ src/components/hotNftCard.js | 2 +- src/components/mostLovedCard.js | 2 +- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/app/collection/[id]/page.js b/src/app/collection/[id]/page.js index 0e539a5..1eaef28 100644 --- a/src/app/collection/[id]/page.js +++ b/src/app/collection/[id]/page.js @@ -6,7 +6,7 @@ import Header1 from '../../../components/header1'; import Footer from '../../../components/footer'; const Collection = ({ params }) => { - const id = params?.id; + const id = params?.id.replace(/-/g, ' ').replace(/\b\w/g, char => char.toUpperCase()); const [phygitals, setPhygitals] = useState([]); const [collections, setCollections] = useState([]); @@ -53,28 +53,28 @@ const Collection = ({ params }) => { const brandData = await brands.json(); // Find the corresponding brand in result - const matchedBrand = result.find(coll => coll.id === id); + const matchedBrand = result.find(coll => coll.name === id); if (matchedBrand) { setCollections(matchedBrand); - } - - // Filter collections by the brand id - const matchedCollections = phygitals.filter(phygital => phygital.collection_id === id); + const CollectionId = matchedBrand.id; - setPhygitals(matchedCollections); + // Filter collections by the brand id + const matchedCollections = phygitals.filter(phygital => phygital.collection_id === CollectionId); - const matchedBrandLogo = brandData.find(brand => brand.id === matchedBrand.brand_id); - if (matchedBrandLogo) { - setLogos(matchedBrandLogo.logo_image); - setDesc(matchedBrandLogo.description); - setBrandId(matchedBrandLogo.id); - setName(matchedBrandLogo.name); - } + setPhygitals(matchedCollections); - setLoading(false); + const matchedBrandLogo = brandData.find(brand => brand.id === matchedBrand.brand_id); + if (matchedBrandLogo) { + setLogos(matchedBrandLogo.logo_image); + setDesc(matchedBrandLogo.description); + setBrandId(matchedBrandLogo.id); + setName(matchedBrandLogo.name); + } - console.log("brand", matchedBrand, matchedCollections, matchedBrandLogo); + setLoading(false); + console.log("brand", matchedBrand, matchedCollections, matchedBrandLogo); + } } catch (error) { console.error('Error fetching data:', error); setLoading(false); @@ -161,7 +161,7 @@ const Collection = ({ params }) => { zIndex: 20, width: '300px', color: 'white' - }} + }} >
{desc}
diff --git a/src/app/nfts/[id]/page.js b/src/app/nfts/[id]/page.js index 815841a..99c2d65 100644 --- a/src/app/nfts/[id]/page.js +++ b/src/app/nfts/[id]/page.js @@ -13,7 +13,7 @@ import Header1 from "@/components/header1"; import axios from 'axios'; import Footer from "@/components/footer"; const NFTPage = ({ params }) => { - const id = params?.id; + const id = params?.id.replace(/-/g, ' ').replace(/\b\w/g, char => char.toUpperCase()); const [isHovered, setIsHovered] = useState(false); const [showPopover, setShowPopover] = useState(false); @@ -55,34 +55,48 @@ const NFTPage = ({ params }) => { const baseUri = process.env.NEXT_PUBLIC_URI || 'https://app.myriadflow.com'; - const phyres = await fetch(`${baseUri}/phygitals/${id}`, { + const nfts = await fetch(`${baseUri}/phygitals/all/554b4903-9a06-4031-98f4-48276c427f78`, { method: 'GET', headers: { 'Content-Type': 'application/json' } }); - const phyresult = await phyres.json() - setonePhygital(phyresult); + const phynfts = await nfts.json(); - const avatar = await fetch(`${baseUri}/avatars/all/554b4903-9a06-4031-98f4-48276c427f78`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' - } - }); + const matchedNft = phynfts.find(nft => nft.name === id); + if (matchedNft) { + const NftId = matchedNft.id; - const avatardata = await avatar.json(); + const phyres = await fetch(`${baseUri}/phygitals/${NftId}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); - console.log("avatar", avatardata, phyresult); + const phyresult = await phyres.json() + setonePhygital(phyresult); - const selectedAvatar = avatardata.find(avatar => avatar.phygital_id === id); + const avatar = await fetch(`${baseUri}/avatars/all/554b4903-9a06-4031-98f4-48276c427f78`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); + + const avatardata = await avatar.json(); + + console.log("avatar", avatardata, phyresult); - // If found, update the state with the avatar URL - if (selectedAvatar) { - setAvatarUrl(selectedAvatar.url); + const selectedAvatar = avatardata.find(avatar => avatar.phygital_id === NftId); + + // If found, update the state with the avatar URL + if (selectedAvatar) { + setAvatarUrl(selectedAvatar.url); + } + setLoading(false); } - setLoading(false); } useEffect(() => { @@ -279,7 +293,7 @@ const NFTPage = ({ params }) => { toast.error('Failed to add to cart. Please try again.'); console.error('Error adding to cart:', error); } - }else{ + } else { toast.warning('Connect your wallet'); } }; diff --git a/src/components/hotNftCard.js b/src/components/hotNftCard.js index 6646647..f24bbd5 100644 --- a/src/components/hotNftCard.js +++ b/src/components/hotNftCard.js @@ -214,7 +214,7 @@ const HotNftCard = ({ nft }) => { return (
- +
- +