@@ -5,13 +5,16 @@ import { trackWindowScroll } from 'react-lazy-load-image-component';
5
5
6
6
import { nftcontractaddress } from '../config'
7
7
import DaturiansNFT from '../artifacts/Daturians.json'
8
- import { getMetadataById } from "../lib/api" ;
8
+ import { getMetadataById , getQueryMetadata } from "../lib/api" ;
9
9
10
10
import NFT from './components/nft' ;
11
+ import SearchBox from './components/search' ;
11
12
12
13
// export default function Home({scrollPosition}) {
13
14
const Home = ( { scrollPosition} ) => {
15
+ const [ totalNfts , setTotalNfts ] = useState ( [ ] )
14
16
const [ nfts , setNfts ] = useState ( [ ] )
17
+ const [ query , setQuery ] = useState ( "" ) ;
15
18
const [ loadingState , setLoadingState ] = useState ( 'not-loaded' )
16
19
const ipfs_gateway = "https://daturians.mypinata.cloud/ipfs/"
17
20
@@ -26,10 +29,7 @@ const Home = ({scrollPosition}) => {
26
29
const contract = new ethers . Contract ( nftcontractaddress , DaturiansNFT . abi , provider )
27
30
// get minted number
28
31
const minted = await contract . totalMinted . call ( ) ;
29
- // console.log(minted.toNumber());
30
- // const data = await contract.walletOfOwner("0x55d9fc8d5f84cf151d9578c6713a0c0ec35e0e5f")
31
32
const data = Array . from ( { length : minted } , ( x , i ) => i + 1 ) ;
32
- // console.log(data);
33
33
34
34
/*
35
35
* map over items returned from smart contract and format
@@ -38,7 +38,6 @@ const Home = ({scrollPosition}) => {
38
38
const ipfsUrl = 'https://daturians.mypinata.cloud/ipfs/QmWeRSySd3RJ9BhoRHzpDsu8PjjNnGYhWwHn44BKDpgvJG/'
39
39
const items = await Promise . all ( data . map ( async i => {
40
40
41
- // let item = await getMetadataById(i, contract);
42
41
const currentUrl = ipfsUrl + String ( i ) + '.json' ;
43
42
const meta = await axios . get ( currentUrl )
44
43
let imgUri = meta . data . image . replace ( "ipfs://" , ipfs_gateway )
@@ -52,45 +51,24 @@ const Home = ({scrollPosition}) => {
52
51
53
52
return item
54
53
} ) )
55
-
54
+ // console.log(items[13])
55
+ setTotalNfts ( items )
56
56
setNfts ( items )
57
57
setLoadingState ( 'loaded' )
58
58
}
59
59
60
- // if (loadingState === 'loaded' && !nfts.length) return (<h1 className="px-20 py-10 text-3xl">No items in marketplace</h1>)
61
- if ( ! nfts . length ) return ( < h1 className = "px-20 py-10 text-3xl" > Loading Daturians NFT</ h1 > )
62
- // return (
63
- // <div className="flex justify-center">
64
- // <div className="px-4" style={{ maxWidth: '1600px' }}>
65
- // <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 pt-4">
66
- // {nfts.map((nft) => (
67
- // <div
68
- // key={nft.tokenId}
69
- // className="border shadow rounded-xl overflow-hidden"
70
- // >
71
- // <Link href={`/single_nft/${nft.tokenId}`}>
72
- // <a>
73
- // <img
74
- // src={nft.image}
75
- // alt={nft.data.image}
76
- // />
77
- // <div className="p-4">
78
- // <p style={{ height: '64px' }} className="text-2xl font-semibold">{nft.name}</p>
79
- // <div style={{ height: '70px', overflow: 'hidden' }}>
80
- // <p className="text-gray-400">{nft.description}</p>
81
- // </div>
82
- // </div>
83
- // </a>
84
- // </Link>
85
- // </div>
86
- // ))}
87
- // </div>
88
- // </div>
89
- // </div>
90
- // )
60
+ const handleSubmit = async ( e ) => {
61
+ await e . preventDefault ( ) ;
62
+ const res = getQueryMetadata ( query , totalNfts ) ;
63
+ setNfts ( res ) ;
64
+ }
65
+
66
+ if ( ! totalNfts . length ) return ( < h1 className = "px-20 py-10 text-3xl" > Loading Daturians NFT</ h1 > )
67
+ // if (!nfts.length) return (<h1 className="px-20 py-10 text-3xl">No Daturians match your search</h1>)
91
68
return (
92
69
< div className = "flex justify-center" >
93
70
< div className = "px-4" style = { { maxWidth : '1600px' } } >
71
+ < SearchBox handleSubmit = { handleSubmit } query = { query } setQuery = { setQuery } />
94
72
< div className = "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 pt-4" >
95
73
{ nfts . map ( ( nft ) => (
96
74
< NFT key = { nft . tokenId } scrollPosition = { scrollPosition } values = { nft } />
0 commit comments