11import React from 'react' ;
2-
32import NFT from '../NFT' ;
43import AppLink from '../AppLink' ;
5- import { OrderDirection , useAccountNftSlotsQuery } from '../../generated/loopringExplorer' ;
4+ import { OrderDirection } from '../../generated/loopringExplorer' ;
65import CursorPagination from '../CursorPagination' ;
6+ import { useAccountNFT } from '../../hooks/useAccountNFT' ;
7+
78
89interface Props {
910 accountId : string ;
1011}
1112
1213const AccountNFTs : React . FC < Props > = ( { accountId } ) => {
1314 const TOTAL_COUNT = 8 ;
14- const { data, fetchMore, error, loading } = useAccountNftSlotsQuery ( {
15- variables : {
16- where : {
17- account : accountId ,
18- balance_gt : 0 ,
19- } ,
20- orderDirection : OrderDirection . Desc ,
21- } ,
22- fetchPolicy : 'cache-and-network' ,
23- } ) ;
15+ const { total, loading, error, data, fetchMore, setSearchInput, searchInput, onClickSearch, feedSearchInput} = useAccountNFT ( accountId )
2416
2517 if ( loading ) {
2618 return null ;
@@ -34,14 +26,50 @@ const AccountNFTs: React.FC<Props> = ({ accountId }) => {
3426 ) ;
3527 }
3628
29+ const totalCount = total ?. accountNFTSlots
30+ ? ( total ?. accountNFTSlots ?. length >= 100 ? "100+" : total ?. accountNFTSlots ?. length )
31+ : "--"
32+
3733 return (
3834 < div >
35+ < div style = { { marginBottom : "10px" } } >
36+ < span style = { {
37+ fontSize : "20px" ,
38+ marginRight : "20px" ,
39+ } } > { totalCount } Items</ span >
40+ < input
41+ type = "text"
42+ name = "query"
43+ className = "gray-color h-10 w-full lg:w-auto flex-1 rounded-xl px-3 py-3 lg:py-0 placeholder-loopring-lightBlue placeholder-opacity-70"
44+ placeholder = "Search NFT by NFT ID"
45+ style = { {
46+ background : "transparent" ,
47+
48+ border : "1px solid rgb(154 161 185 / var(--tw-text-opacity))" ,
49+ width : "300px" ,
50+ } }
51+ value = { searchInput }
52+ onInput = { ( e ) => {
53+ setSearchInput ( e . currentTarget . value )
54+ } }
55+ />
56+ < button
57+ type = "submit"
58+ className = "bg-loopring-darkBlue mt-4 lg:mt-0 py-1 px-10 ml-2 rounded-xl text-white h-10 dark:bg-loopring-dark-blue"
59+ onClick = { ( ) => {
60+ onClickSearch ( )
61+ } }
62+ >
63+ Search
64+ </ button >
65+ </ div >
3966 { data . accountNFTSlots . length === 0 ? (
4067 < div className = "text-gray-400 text-2xl h-40 flex items-center justify-center w-full border" >
4168 No NFTs to show
4269 </ div >
4370 ) : (
4471 < >
72+
4573 < div className = "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2" >
4674 { data . accountNFTSlots . map ( ( slot , index ) => {
4775 const { id, balance, nft } = slot ;
@@ -66,24 +94,42 @@ const AccountNFTs: React.FC<Props> = ({ accountId }) => {
6694 } ) }
6795 </ div >
6896 < CursorPagination
69- onNextClick = { ( fetchNext , afterCursor ) =>
97+ onNextClick = { ( fetchNext , afterCursor ) => {
7098 fetchNext ( {
7199 variables : {
72100 where : {
73101 account : accountId ,
74102 id_lt : afterCursor ,
75103 balance_gt : 0 ,
104+ ...(
105+ feedSearchInput
106+ ? {
107+ nft_ : {
108+ nftID : feedSearchInput
109+ }
110+ }
111+ : { }
112+ )
76113 } ,
77114 } ,
78115 } )
79- }
116+ } }
80117 onPreviousClick = { ( fetchPrevious , beforeCursor ) =>
81118 fetchPrevious ( {
82119 variables : {
83120 where : {
84121 account : accountId ,
85122 id_gt : beforeCursor ,
86123 balance_gt : 0 ,
124+ ...(
125+ feedSearchInput
126+ ? {
127+ nft_ : {
128+ nftID : feedSearchInput
129+ }
130+ }
131+ : { }
132+ )
87133 } ,
88134 orderDirection : OrderDirection . Asc ,
89135 } ,
0 commit comments