From a45a5b6a6905a5e00db188d24680e125401d0c88 Mon Sep 17 00:00:00 2001 From: Suraj Mahto Date: Mon, 28 Oct 2024 00:12:32 +0530 Subject: [PATCH] feat : changed brand page url path --- src/app/brand/[id]/page.js | 369 ++++++++++++++++++------------------- src/app/brands/page.js | 2 +- 2 files changed, 184 insertions(+), 187 deletions(-) diff --git a/src/app/brand/[id]/page.js b/src/app/brand/[id]/page.js index d9d23a6..99b7c0b 100644 --- a/src/app/brand/[id]/page.js +++ b/src/app/brand/[id]/page.js @@ -1,163 +1,160 @@ "use client" -import React, {useState, useEffect} from 'react' +import React, { useState, useEffect } from 'react' import Link from 'next/link'; import MostLovedCard from "../../../components/mostLovedCard"; import HotNftCard from "../../../components/hotNftCard"; import Header1 from '../../../components/header1' import Footer from '../../../components/footer' -const Brand = ({params}) => { - - const id = params?.id; - - const [brand, setBrand] = useState([]); - const [collections, setcollections] = useState([]); - const [nfts, setnfts] = useState([]) - const [loading, setloading] = useState(false); - - useEffect(() => { - const brandmatch = async() => { - setloading(true); - const baseUri = process.env.NEXT_PUBLIC_URI || 'https://app.myriadflow.com'; - - try { - const res = await fetch(`${baseUri}/brands/all/554b4903-9a06-4031-98f4-48276c427f78`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' - } - }); - - const phyres = await fetch(`${baseUri}/collections/all/554b4903-9a06-4031-98f4-48276c427f78`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' - } - }); - - const nfts = await fetch(`${baseUri}/phygitals/all/554b4903-9a06-4031-98f4-48276c427f78`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' +const Brand = ({ params }) => { + const brandName = params?.id.replace(/-/g, ' '); + + const [brand, setBrand] = useState([]); + const [collections, setcollections] = useState([]); + const [nfts, setnfts] = useState([]) + const [loading, setloading] = useState(false); + + useEffect(() => { + const brandmatch = async () => { + setloading(true); + const baseUri = process.env.NEXT_PUBLIC_URI || 'https://app.myriadflow.com'; + + try { + const res = await fetch(`${baseUri}/brands/all/554b4903-9a06-4031-98f4-48276c427f78`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); + + const phyres = await fetch(`${baseUri}/collections/all/554b4903-9a06-4031-98f4-48276c427f78`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); + + const nfts = await fetch(`${baseUri}/phygitals/all/554b4903-9a06-4031-98f4-48276c427f78`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); + + if (!res.ok || !phyres.ok || !nfts.ok) { + throw new Error('Failed to fetch data'); } - }); - - if (!res.ok || !phyres.ok || !nfts.ok) { - throw new Error('Failed to fetch data'); - } - - const result = await res.json(); - const collections = await phyres.json(); - const phynfts = await nfts.json(); - - // Find the corresponding brand in result - const matchedBrand = result.find(brand => brand.id === id); - if (matchedBrand) { - setBrand(matchedBrand); - } - - // Filter collections by the brand id - const matchedCollections = collections.filter(collection => collection.brand_id === id); - - // Extract the IDs of the matched collections -const matchedCollectionIds = matchedCollections.map(collection => collection.id); - -// Filter NFTs by the matched collection IDs -const matchedNFTs = phynfts.filter(nft => matchedCollectionIds.includes(nft.collection_id)); - - setcollections(matchedCollections); - setnfts(matchedNFTs) - setloading(false); - - console.log("phynfts", phynfts); - - } catch (error) { - console.error('Error fetching data:', error); - setloading(false); - } + + const result = await res.json(); + const collections = await phyres.json(); + const phynfts = await nfts.json(); + + // Find the corresponding brand in result + const matchedBrand = result.find(brand => brand.name === brandName); + if (matchedBrand) { + setBrand(matchedBrand); + const brandId = matchedBrand.id; + // console.log("Brand Id",brandid) + + + // Filter collections by the brand id + const matchedCollections = collections.filter(collection => collection.brand_id === brandId); + + // Extract the IDs of the matched collections + const matchedCollectionIds = matchedCollections.map(collection => collection.id); + + // Filter NFTs by the matched collection IDs + const matchedNFTs = phynfts.filter(nft => matchedCollectionIds.includes(nft.collection_id)); + + setcollections(matchedCollections); + setnfts(matchedNFTs) + setloading(false); } - - brandmatch(); - }, []) + } catch (error) { + console.error('Error fetching data:', error); + setloading(false); + } + } + + brandmatch(); + }, []) + - return ( -<> -
- -
-
- {brand?.name} - - {brand?.name} -
- -
- -
- {brand?.name} -
+ <>
-
- {brand?.description} + +
+
+ {brand?.name} + + {brand?.name} +
+ +
+ +
+ {brand?.name}
+
+
+ {brand?.description} +
- -
SHARE
+ backgroundOrigin: "border-box", + backgroundClip: "content-box, border-box", + WebkitBackgroundClip: "content-box, border-box", // For Safari + display: "block", + width: "180px", + height: "50px", + textAlign: 'center', + }} + > +
SHARE
-
+
-
+
{brand.website && ( Website @@ -183,7 +180,7 @@ const matchedNFTs = phynfts.filter(nft => matchedCollectionIds.includes(nft.coll Website )} - {brand.additional_link && brand.additional_link === 'whatsapp' && ( + {brand.additional_link && brand.additional_link === 'whatsapp' && ( WhatsApp @@ -224,61 +221,61 @@ const matchedNFTs = phynfts.filter(nft => matchedCollectionIds.includes(nft.coll )} -
+
-
Collections
+
Collections
- {collections?.map((nft, index) => ( - - ))} -
+ {collections?.map((nft, index) => ( + + ))} +
-
Phygitals
+
Phygitals
+ +
+ {nfts?.map((nft, index) => ( + + ))} +
-
- {nfts?.map((nft, index) => ( - - ))}
-
- -
-
-
- - - {loading && ( -
-
-
-
- Loading icon -
+
+
-
-
-)} + + + {loading && ( +
+
+
+
+ Loading icon +
+
+
+
+ )} ) diff --git a/src/app/brands/page.js b/src/app/brands/page.js index 7058458..e30596f 100644 --- a/src/app/brands/page.js +++ b/src/app/brands/page.js @@ -78,7 +78,7 @@ const Page = () => {
{brands?.map((brand, index) => ( - +