Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
siinghd committed Apr 3, 2024
1 parent 58db603 commit 7b5747e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions apps/www/app/themes/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as React from "react"

import { useConfig } from "@/hooks/use-config"
import { ThemeWrapper } from "@/components/theme-wrapper"
import CardsDefault from "@/registry/default/example/cards"
import { Skeleton } from "@/registry/default/ui/skeleton"

export function ThemesTabs() {
Expand Down Expand Up @@ -62,9 +61,10 @@ export function ThemesTabs() {
</div>
</div>
) : (
<ThemeWrapper>
{config.style === "default" && <CardsDefault />}
</ThemeWrapper>
""
// <ThemeWrapper>
// {config.style === "default" && <CardsDefault />}
// </ThemeWrapper>
)}
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion apps/www/public/registry/styles/default/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"files": [
{
"name": "collection.tsx",
"content": "import { useEffect, useState } from \"react\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\n\n\nimport { cn } from \"@/lib/utils\";\n\n\n\nimport Loading from \"./loading\";\nimport { Pagination, PaginationContent, PaginationItem, PaginationNext, PaginationPrevious } from \"./pagination\";\n\n\nconst collectionVariants = cva(\n \"inline-flex flex-col rounded-lg border p-4 transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2\",\n {\n variants: {\n variant: {\n default: \"border-gray-200 bg-white text-black hover:bg-gray-50\",\n dark: \"border-gray-700 bg-gray-800 text-white hover:bg-gray-700\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n },\n }\n)\n\ninterface CollectionProps\n extends React.HTMLAttributes<HTMLDivElement>,\n VariantProps<typeof collectionVariants> {\n collectionName: string\n limit?: number\n}\n\nconst Collection = ({\n className,\n variant,\n collectionName,\n limit = 2,\n ...props\n}: CollectionProps) => {\n const [collection, setCollection] = useState<any>(null)\n const [currentPageKey, setCurrentPageKey] = useState<string>(\"\")\n const [pageKeys, setPageKeys] = useState<string[]>([])\n const [loading, setLoading] = useState(false)\n useEffect(() => {\n setLoading(true)\n const cacheKeyPrefix = `collectionData-${collectionName}-${limit}`\n const cacheKey = `${cacheKeyPrefix}-${currentPageKey}`\n const fetchCollectionData = async () => {\n const cachedData = sessionStorage.getItem(cacheKey)\n if (cachedData) {\n setCollection(JSON.parse(cachedData))\n } else {\n let url = `https://solanaapi.nftscan.com/api/sol/assets/collection/${collectionName}?show_attribute=false&limit=${Math.min(\n limit,\n 100\n )}&cursor=${currentPageKey}`\n if (currentPageKey) url += `&page=${currentPageKey}`\n try {\n const response = await fetch(url, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"*/*\",\n \"X-API-KEY\": process.env.NEXT_PUBLIC_NFTSCAN_KEY!,\n },\n })\n const jsonData = await response.json()\n if (jsonData.code === 200) {\n try {\n sessionStorage.setItem(cacheKey, JSON.stringify(jsonData.data))\n } catch (e) {\n clearCache(cacheKeyPrefix)\n sessionStorage.setItem(cacheKey, JSON.stringify(jsonData.data))\n }\n setCollection(jsonData.data)\n } else {\n console.error(\"Failed to fetch collection data:\", jsonData.message)\n }\n } catch (error) {\n console.error(\"Error fetching collection data:\", error)\n }\n }\n setLoading(false)\n }\n\n fetchCollectionData()\n }, [collectionName, currentPageKey])\n\n const clearCache = (prefix: string) => {\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i)\n if (key && key.startsWith(prefix)) {\n sessionStorage.removeItem(key)\n }\n }\n }\n\n const handlePreviousPage = () => {\n if (pageKeys.length === 0) return\n const newPageKeys = [...pageKeys]\n newPageKeys.pop()\n const previousPageKey = newPageKeys[newPageKeys.length - 1] || \"\"\n\n setCurrentPageKey(previousPageKey)\n setPageKeys(newPageKeys)\n }\n\n const handleNextPage = () => {\n if (collection?.next) {\n const newPageKeys = [...pageKeys, collection.next]\n setPageKeys(newPageKeys)\n setCurrentPageKey(collection.next)\n }\n }\n\n const CollectionNftCard = (nft: any) => {\n return (\n <div className=\"border border-gray-200 dark:border-gray-800 rounded-lg\">\n <div className=\"aspect-[4/3] w-full overflow-hidden rounded-t-lg\">\n <img\n alt={nft.name}\n className=\"object-cover\"\n height={300}\n src={`https://images.hsingh.site/?url=${nft.image_uri}&output=webp&width=400&q=80w=400&h=400`}\n style={{\n aspectRatio: \"400/300\",\n objectFit: \"cover\",\n }}\n width={400}\n />\n </div>\n <div className=\"p-4 grid gap-2\">\n <h2 className=\"text-lg font-semibold leading-none\">{nft.name}</h2>\n <p className=\"text-sm font-medium leading-none text-gray-500 dark:text-gray-400\">\n by {nft.collection}\n </p>\n </div>\n </div>\n )\n }\n return (\n <div>\n {loading ? (\n <Loading />\n ) : (\n <div className=\"grid md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-6\">\n {collection?.content?.map((nft: any) => (\n <CollectionNftCard {...nft} key={nft.token_address} />\n ))}\n </div>\n )}\n <div className=\"flex justify-center items-center gap-4 text-sm mt-5\">\n <Pagination>\n <PaginationContent className=\"m-0\">\n {pageKeys.length > 0 && (\n <PaginationItem>\n <button onClick={handlePreviousPage}>\n <PaginationPrevious href=\"#\" />\n </button>\n </PaginationItem>\n )}\n\n <PaginationItem>\n <button onClick={handleNextPage}>\n <PaginationNext href=\"#\" />\n </button>\n </PaginationItem>\n </PaginationContent>\n </Pagination>\n </div>\n </div>\n )\n}\nCollection.displayName = \"Collection\"\nexport { Collection, collectionVariants }"
"content": "import { useEffect, useState } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\n\nimport Loading from \"./loading\"\nimport {\n Pagination,\n PaginationContent,\n PaginationItem,\n PaginationNext,\n PaginationPrevious,\n} from \"./pagination\"\n\nconst collectionVariants = cva(\n \"inline-flex flex-col rounded-lg border p-4 transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2\",\n {\n variants: {\n variant: {\n default: \"border-gray-200 bg-white text-black hover:bg-gray-50\",\n dark: \"border-gray-700 bg-gray-800 text-white hover:bg-gray-700\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n },\n }\n)\n\ninterface CollectionProps\n extends React.HTMLAttributes<HTMLDivElement>,\n VariantProps<typeof collectionVariants> {\n collectionName: string\n limit?: number\n}\n\nconst Collection = ({\n className,\n variant,\n collectionName,\n limit = 2,\n ...props\n}: CollectionProps) => {\n const [collection, setCollection] = useState<any>(null)\n const [currentPageKey, setCurrentPageKey] = useState<string>(\"\")\n const [pageKeys, setPageKeys] = useState<string[]>([])\n const [loading, setLoading] = useState(false)\n useEffect(() => {\n setLoading(true)\n const cacheKeyPrefix = `collectionData-${collectionName}-${limit}`\n const cacheKey = `${cacheKeyPrefix}-${currentPageKey}`\n const fetchCollectionData = async () => {\n const cachedData = sessionStorage.getItem(cacheKey)\n if (cachedData) {\n setCollection(JSON.parse(cachedData))\n } else {\n let url = `https://solanaapi.nftscan.com/api/sol/assets/collection/${collectionName}?show_attribute=false&limit=${Math.min(\n limit,\n 100\n )}&cursor=${currentPageKey}`\n if (currentPageKey) url += `&page=${currentPageKey}`\n try {\n const response = await fetch(url, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"*/*\",\n \"X-API-KEY\": process.env.NEXT_PUBLIC_NFTSCAN_KEY!,\n },\n })\n const jsonData = await response.json()\n if (jsonData.code === 200) {\n try {\n sessionStorage.setItem(cacheKey, JSON.stringify(jsonData.data))\n } catch (e) {\n clearCache(cacheKeyPrefix)\n sessionStorage.setItem(cacheKey, JSON.stringify(jsonData.data))\n }\n setCollection(jsonData.data)\n } else {\n console.error(\"Failed to fetch collection data:\", jsonData.message)\n }\n } catch (error) {\n console.error(\"Error fetching collection data:\", error)\n }\n }\n setLoading(false)\n }\n\n fetchCollectionData()\n }, [collectionName, currentPageKey])\n\n const clearCache = (prefix: string) => {\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i)\n if (key && key.startsWith(prefix)) {\n sessionStorage.removeItem(key)\n }\n }\n }\n\n const handlePreviousPage = () => {\n if (pageKeys.length === 0) return\n const newPageKeys = [...pageKeys]\n newPageKeys.pop()\n const previousPageKey = newPageKeys[newPageKeys.length - 1] || \"\"\n\n setCurrentPageKey(previousPageKey)\n setPageKeys(newPageKeys)\n }\n\n const handleNextPage = () => {\n if (collection?.next) {\n const newPageKeys = [...pageKeys, collection.next]\n setPageKeys(newPageKeys)\n setCurrentPageKey(collection.next)\n }\n }\n\n const CollectionNftCard = (nft: any) => {\n return (\n <div className=\"border border-gray-200 dark:border-gray-800 rounded-lg\">\n <div className=\"aspect-[4/3] w-full overflow-hidden rounded-t-lg\">\n <img\n alt={nft.name}\n className=\"object-cover\"\n height={300}\n src={`https://images.hsingh.site/?url=${nft.image_uri}&output=webp&width=400&q=80w=400&h=400`}\n style={{\n aspectRatio: \"400/300\",\n objectFit: \"cover\",\n }}\n width={400}\n />\n </div>\n <div className=\"p-4 grid gap-2\">\n <h2 className=\"text-lg font-semibold leading-none\">{nft.name}</h2>\n <p className=\"text-sm font-medium leading-none text-gray-500 dark:text-gray-400\">\n by {nft.collection}\n </p>\n </div>\n </div>\n )\n }\n return (\n <div>\n {loading ? (\n <Loading />\n ) : (\n <div className=\"grid md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-6\">\n {collection?.content?.map((nft: any) => (\n <CollectionNftCard {...nft} key={nft.token_address} />\n ))}\n </div>\n )}\n <div className=\"flex justify-center items-center gap-4 text-sm mt-5\">\n <Pagination>\n <PaginationContent className=\"m-0\">\n {pageKeys.length > 0 && (\n <PaginationItem>\n <button onClick={handlePreviousPage}>\n <PaginationPrevious href=\"#\" />\n </button>\n </PaginationItem>\n )}\n\n {collection?.next && (\n <PaginationItem>\n <button onClick={handleNextPage}>\n <PaginationNext href=\"#\" />\n </button>\n </PaginationItem>\n )}\n </PaginationContent>\n </Pagination>\n </div>\n </div>\n )\n}\nCollection.displayName = \"Collection\"\nexport { Collection, collectionVariants }\n"
}
],
"type": "components:ui"
Expand Down
Loading

0 comments on commit 7b5747e

Please sign in to comment.