generated from t3-oss/create-t3-turbo
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcollection-items-data-grid-view.tsx
169 lines (160 loc) · 5.69 KB
/
collection-items-data-grid-view.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { forwardRef } from "react";
import Link from "next/link";
import { LoaderCircle } from "lucide-react";
import { VirtuosoGrid } from "react-virtuoso";
import { cn, ellipsableStyles, formatUnits } from "@ark-market/ui";
import {
NftCard,
NftCardAction,
NftCardContent,
NftCardMedia,
} from "@ark-market/ui/nft-card";
import type { ViewType } from "../../../../components/view-type-toggle-group";
import type { CollectionToken } from "~/types";
import Media from "~/components/media";
import CollectionItemsBuyNow from "./collection-items-buy-now";
const LargeGridContainer = forwardRef<
HTMLDivElement,
React.ComponentPropsWithoutRef<"div">
>(({ children, ...props }, ref) => (
<div
ref={ref}
{...props}
className="mb-2 grid w-full grid-cols-2 gap-4 px-5 py-6 sm:grid-cols-[repeat(auto-fill,_minmax(15rem,1fr))] sm:gap-2"
>
{children}
</div>
));
LargeGridContainer.displayName = "LargeGridContainer";
const SmallGridContainer = forwardRef<
HTMLDivElement,
React.ComponentPropsWithoutRef<"div">
>(({ children, ...props }, ref) => (
<div
ref={ref}
{...props}
className="mb-2 grid w-full grid-cols-2 gap-4 px-5 py-6 sm:grid-cols-[repeat(auto-fill,_minmax(10rem,1fr))] sm:gap-2"
>
{children}
</div>
));
SmallGridContainer.displayName = "SmallGridContainer";
interface CollectionItemsDataGridViewProps {
items: CollectionToken[];
viewType: ViewType;
onEndReached: () => void;
}
export default function CollectionItemsDataGridView({
items,
viewType,
onEndReached,
}: CollectionItemsDataGridViewProps) {
const components = {
List: viewType === "large-grid" ? LargeGridContainer : SmallGridContainer,
};
return (
<div className="mb-6">
<VirtuosoGrid
initialTopMostItemIndex={0}
overscan={400}
totalCount={items.length}
useWindowScroll
components={components}
endReached={onEndReached}
itemContent={(index) => {
const token = items[index];
if (!token) {
return null;
}
return (
<NftCard>
<Link
href={`/token/${token.collection_address}/${token.token_id}`}
key={`${token.collection_address}-${token.token_id}`}
prefetch={false}
>
<NftCardMedia>
<Media
src={token.metadata?.image}
mediaKey={token.metadata?.image_key}
thumbnailKey={token.metadata?.image_key_540_540}
alt={token.metadata?.name ?? "Empty"}
className="aspect-square w-full object-contain transition-transform group-hover:scale-110"
height={viewType === "large-grid" ? 540 : 340}
width={viewType === "large-grid" ? 540 : 340}
/>
</NftCardMedia>
<NftCardContent>
<div className="flex w-full justify-between">
<div className="w-full">
<div
className={cn(
"font-bold",
viewType === "large-grid" ? "text-xl" : "text-sm",
ellipsableStyles,
)}
>
{token.metadata?.name ?? token.token_id}
</div>
{token.price ? (
<div
className={cn(
"font-medium",
viewType === "large-grid" ? "text-sm" : "text-xs",
ellipsableStyles,
)}
>
{formatUnits(token.price, 18)}{" "}
<span className="text-muted-foreground">ETH</span>
</div>
) : (
<div
className={cn(
"font-medium",
viewType === "large-grid" ? "text-sm" : "text-xs",
ellipsableStyles,
)}
>
Not for sale
</div>
)}
</div>
</div>
<p className="mt-5 h-5 text-sm font-medium text-secondary-foreground">
{token.last_price ? (
<>
Last {viewType === "large-grid" ? "sale" : ""}{" "}
{formatUnits(token.last_price, 18)} ETH
</>
) : null}
</p>
</NftCardContent>
</Link>
{token.buy_in_progress ? (
<div
className={cn(
"absolute bottom-0 left-0 flex h-10 w-full items-center justify-between gap-2 bg-primary px-3 font-medium text-background",
viewType === "large-grid" ? "text-sm" : "text-sm",
)}
>
<span className="leading-none">Buy in progress</span>
<LoaderCircle className="left-4 size-4 animate-spin" />
</div>
) : token.is_listed && !token.listing.is_auction ? (
<CollectionItemsBuyNow token={token} />
) : (
<NftCardAction asChild>
<Link
href={`/token/${token.collection_address}/${token.token_id}`}
>
Details
</Link>
</NftCardAction>
)}
</NftCard>
);
}}
/>
</div>
);
}