import { Box, BoxProps, Center, Code, Flex, HStack, Icon, IconButton, Image, ImageProps, Portal, Select, Table, Tbody, Td, Th, Thead, Tr, } from "@chakra-ui/react"; import { NFTMetadata } from "@thirdweb-dev/sdk"; import { useImageFileOrUrl } from "hooks/useImageFileOrUrl"; import { useMemo } from "react"; import { MdFirstPage, MdLastPage, MdNavigateBefore, MdNavigateNext, } from "react-icons/md"; import { Column, usePagination, useTable } from "react-table"; import { Text } from "tw-components"; import { parseDescription } from "utils/parseDescription"; const FileImage: React.FC = ({ src, ...props }) => { const img = useImageFileOrUrl(src); return ; }; const FileVideo: React.FC< BoxProps & Omit, "ref"> > = ({ src, ...props }) => { const video = useImageFileOrUrl(src); return ; }; interface BatchTableProps { data: NFTMetadata[]; portalRef: React.RefObject; nextTokenIdToMint?: number; } export const BatchTable: React.FC = ({ data, portalRef, nextTokenIdToMint, }) => { const columns = useMemo(() => { return [ { Header: "Token ID", accessor: (_row, index) => nextTokenIdToMint ? nextTokenIdToMint + index : index, }, { Header: "Image", accessor: (row) => row.image, Cell: ({ cell: { value } }: { cell: { value?: string } }) => // We do this so users can see a preview of their IPFS hashes when batch uploading typeof value === "string" && value.startsWith("ipfs://") ? ( ) : value ? ( ) : null, }, { Header: "Animation Url", accessor: (row) => row.animation_url, Cell: ({ cell: { value } }: { cell: { value?: string } }) => // We do this so users can see a preview of their IPFS hashes when batch uploading typeof value === "string" && value.startsWith("ipfs://") ? ( ) : value ? ( ) : null, }, { Header: "Name", accessor: (row) => row.name }, { Header: "Description", accessor: (row) => parseDescription(row.description), }, { Header: "Properties", accessor: (row) => row.attributes || row.properties, Cell: ({ cell }: { cell: any }) => ( {JSON.stringify(cell.value, null, 2)} ), }, { Header: "External URL", accessor: (row) => row.external_url }, { Header: "Background Color", accessor: (row) => row.background_color }, ] as Column[]; }, [nextTokenIdToMint]); const { getTableProps, getTableBodyProps, headerGroups, prepareRow, // Instead of using 'rows', we'll use page, page, // which has only the rows for the active page // The rest of these things are super handy, too ;) canPreviousPage, canNextPage, pageOptions, pageCount, gotoPage, nextPage, previousPage, setPageSize, state: { pageIndex, pageSize }, } = useTable( { columns, data, initialState: { pageSize: 50, pageIndex: 0, }, }, usePagination, ); // Render the UI for your table return ( {headerGroups.map((headerGroup) => ( // eslint-disable-next-line react/jsx-key {headerGroup.headers.map((column) => ( // eslint-disable-next-line react/jsx-key ))} ))} {page.map((row) => { prepareRow(row); return ( // eslint-disable-next-line react/jsx-key {row.cells.map((cell) => { return ( // eslint-disable-next-line react/jsx-key ); })} ); })}
{column.render("Header")}
{cell.render("Cell")}
} onClick={() => gotoPage(0)} /> } onClick={() => previousPage()} /> Page {pageIndex + 1} of{" "} {pageOptions.length} } onClick={() => nextPage()} /> } onClick={() => gotoPage(pageCount - 1)} />
); };