Skip to content

Commit

Permalink
fix: collection list table view
Browse files Browse the repository at this point in the history
  • Loading branch information
MartianGreed committed Nov 4, 2024
1 parent 0a7b300 commit 9484a7e
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useRef } from "react";
import { useMemo, useRef } from "react";
import { useWindowVirtualizer } from "@tanstack/react-virtual";

import { cn, ellipsableStyles, formatUnits } from "@ark-market/ui";
Expand All @@ -19,6 +19,7 @@ import type { CollectionToken } from "~/types";
import Media from "~/components/media";
import { PriceTag } from "@ark-market/ui/price-tag";
import Link from "next/link";
import { env } from "~/env";

const gridTemplateColumnValue =
"grid-cols-[minmax(10rem,2fr)_repeat(5,minmax(7.25rem,1fr))]";
Expand All @@ -32,11 +33,17 @@ export default function CollectionItemsDataListView({
}: CollectionItemsDataListViewProps) {
const tableRef = useRef<HTMLTableElement | null>(null);


// Filtering out tokens client side to only display token listed out in lords or not listed
const tokens = useMemo(() => collectionTokens.filter((token) => {
return token.listing === null || token.listing.currency.contract === env.NEXT_PUBLIC_LORDS_TOKEN_ADDRESS;
}), [collectionTokens]);

const rowVirtualizer = useWindowVirtualizer({
// Approximate initial rect for SSR
initialRect: { height: 1080, width: 1920 },
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
count: collectionTokens.length ?? 0,
count: tokens.length ?? 0,
estimateSize: () => 75, // Estimation of row height for accurate scrollbar dragging
// Measure dynamic row height, except in firefox because it measures table border height incorrectly
measureElement:
Expand Down Expand Up @@ -78,7 +85,7 @@ export default function CollectionItemsDataListView({
}}
>
{rowVirtualizer.getVirtualItems().map((virtualRow) => {
const token = collectionTokens[virtualRow.index];
const token = tokens[virtualRow.index];

if (!token) {
return null;
Expand Down

0 comments on commit 9484a7e

Please sign in to comment.