diff --git a/next_app/src/components/views/components/marketplace.tsx b/next_app/src/components/views/components/marketplace.tsx index 89d9bb2..7ab3edb 100644 --- a/next_app/src/components/views/components/marketplace.tsx +++ b/next_app/src/components/views/components/marketplace.tsx @@ -25,7 +25,7 @@ import { extractHandlerNames } from "@/lib/utils"; import { AOProfileType, getProfileById } from "@/lib/bazar"; import Image from "next/image"; -function Template({ pid }: { pid: string }) { +function Template({ pid, search }: { pid: string, search: string }) { const [hovered, setHovered] = useState(false) const [txData, setTxData] = useState(null) const [assetTags, setAssetTags] = useState<{ [name: string]: string }>({ @@ -125,7 +125,6 @@ function Template({ pid }: { pid: string }) { if (!creator) return getProfileById({ profileId: creator }).then((profile) => { - console.log("profile", profile) setProfile(profile) }) }, [assetTags]) @@ -142,6 +141,31 @@ function Template({ pid }: { pid: string }) { console.log("clicked") } + const search_ = search.trim().toLowerCase() + + // if (assetTags['Title'].toLowerCase().includes(search.toLowerCase()) + // || assetTags['Description'].toLowerCase().includes(search.toLowerCase()) + // || pid.toLowerCase().includes(search.toLowerCase()) + // || profile?.displayName.toLowerCase().includes(search.toLowerCase()) + + // ) + + function compare(lhs: string, rhs: string) { + if (!lhs || !rhs) return false + return lhs.trim().toLowerCase().includes(rhs.trim().toLowerCase()) + } + + if (search_ && !( + compare(assetTags['Title'], search_) + || compare(assetTags['Description'], search_) + || compare(pid, search_) + || compare(profile?.displayName, search_) + || compare(profile?.username, search_) + )) { + return null + } + + return
([]) + const [search, setSearch] = useState("") + + useEffect(() => { + function fetchAssets() { + if (!search) return + if (search.length == 43) return + + const gqlQuery = gql`query { + transactions( + tags:[{ + name:"BetterIDEa-Template", + values:["BetterIDEa-Template"] + }] + ) { + edges { + node { + id + tags { + name + value + } + } + } + } +}` + const client = new GraphQLClient("https://arweave.net/graphql") + client.request(gqlQuery).then((data) => { + const node = (data as any).transactions.edges.map((edge) => edge.node) + const ids = node.map((n) => n.id) + console.log(ids) + setAssetIds(ids) + }).catch((e) => { + console.error(e) + toast.error("Error fetching transaction data") + }) + } + const t = setTimeout(fetchAssets, 500) + + return () => clearTimeout(t) + }, [search]) + + useEffect(() => { + console.log(search) + }, [search]) return
Template Marketplace (BETA)
- + { + const v = e.target.value + if (v.length == 43) { + setAssetIds([v]) + setSearch("") + } + else + setSearch(e.target.value) + }} />
- {Array.from({ length: 10 }).map((_, i) =>