* init solana dashboard * some updates * deploying programs works? * solana program page is go * more updates * various updates and improvements * git add maybe? * working state * working minting / nft list * working drop lazy mint + latest nightly * dashboard works * forgot to add things * fix various small things * fix rpc * implement token page + code organization * update SDK * rename accounts to program * implement token mint button * split dashboard into evm vs sol and separate out solana programs * fix caching * upgrade to combined sdk * merge in main * update to latest nightly SDK * tabs for days * lul query client maybe? * remove unused hook * add super basic nft drawer * lots of updates to start on nft drawer etc * add code tab content * fix merge conflicts * pass program address to code tab * some changes * some minor updates * new nft drawer and table * drawer for solana done (v1) * fix a bunch of stuff * fix some tracking * update nightly * add programId to program deploy event * adapt to changes in react lib * upgrade to dev version * Add batch upload to Solana (#539) * First small necessary refactor * Working version * Working version with yalc * Use nightly * Move everything around * Remove unused imports * Fix types * Add state for hasTried * Fix conditions * Add solana * Move selectedReveal to be part of the form * Improve logic * Update dependencies * Make drawer fullscreen * Fix hasFailed logic * Fix types * Make inputs required conditionally * Fix types * Make loading work * Remove repeated code * Remove unused * Pass progress as a prop * Move common files to core-ui * massive cleanup Co-authored-by: Jonas Daniels <[email protected]> * feat(faucet): build solana faucet (#528) * feat(faucet): build solana faucet * chore: update names * fix: type Co-authored-by: Jonas Daniels <[email protected]> * fix: minor stuff Co-authored-by: Jonas Daniels <[email protected]> * fix: feedback * feat: minor improvements * feat: add faq section * refactor: refactor faq * add accordion * minor fix Co-authored-by: Jonas Daniels <[email protected]> * tiny fix * Revert batch upload styles (#541) * Fix typo, fix drawer width * Revert to old batch upload styles * Fix some more styles * Fix progress bar styles * Update to using TWRegistry * [Solana] Add claim conditions to NFT Drop (#542) * Add tab and getter * Working version * Delete unused imports * Currency selector works but I hate it * Add maxClaimable * Fix build issue * Make batch upload work again * Fix claim conditions for devnet * Test fix * Delete console.logs * A lot of solana stuff (#545) * Remove unused banner * Hide Claim Conditions tab for no drops * Add loading state * Remove comment * Add helper text for nft drop supply * Delete log * Add loading state to program list * Add redirect if you don't have any program deploys * Add default instant reveal for Solana * Fix styles * Fix logic * doc fixes * fix(faucet): minor issues (#543) * fix(spacing): fix spacing in faq * feat: some updates from feedback * fix: use linkButton * feat: use fetch * remove test code * fix: err handling * pass err * fix sucecss state * fix: link * some updates * small fixes Co-authored-by: Nacho Iacovino <[email protected]> * update to latest nightly * fix up form and update deps * Add claim button to Solana (#555) * wip * Add claim buttons, fix warning, disable buttons conditioanlly * Use nightly * Delete unused import * Solana hackathon landing (#554) * feat: build hackathon page (#547) * wip: build hackathon page * add some more stuff * feat: responsievness and some minor stuff Co-authored-by: Nacho Iacovino <[email protected]> * First section * Fix PrizeSection * Add link to register now * Add judges and footer * Update startTime for hackathon * Fix Schedule * Add tracking * Add pageId * Prettier? * Prettier again * Prettier you're drunk * This is my life now * Remove unused import * Add og metadata * Update SEO Co-authored-by: Avneesh Agarwal <[email protected]> Co-authored-by: Jonas Daniels <[email protected]> * Add solana landing page (#556) * Add landing page for Solana * Add solana landing page * Add shopify landing * Add shopify * Remove quote * Add meta tags * Add landing page updates * Add links * small cleanups * fix various & pagination on nft table solana * Show unclaimed instead of tokenId for lazy minted tokens * add full install command for solana react * show create cli command in code tab for react * add funds notice for solana * add various things * various updates * various updates * updated some guides and copy based on juan feedback * Fix Solana faucet link * Add disclaimer on how to deploy with Devnet * Small fixes * Update guidelines * Fix currency selector bug * Update hero copy * fix build issues * update to latest * link solana cards * Add partners * update og images for shopify & solana * Add solanathon og:image * copy changes * Update image size * Center sponsors Co-authored-by: Joaquim Verges <[email protected]> Co-authored-by: Nacho Iacovino <[email protected]> Co-authored-by: Avneesh Agarwal <[email protected]> Co-authored-by: Nacho Iacovino <[email protected]> Co-authored-by: Adam Majmudar <[email protected]>
269 lines
7.3 KiB
TypeScript
269 lines
7.3 KiB
TypeScript
import {
|
|
ButtonGroup,
|
|
Center,
|
|
Divider,
|
|
Flex,
|
|
Icon,
|
|
Spinner,
|
|
Table,
|
|
Tbody,
|
|
Td,
|
|
Th,
|
|
Thead,
|
|
Tr,
|
|
} from "@chakra-ui/react";
|
|
import {
|
|
ColumnDef,
|
|
PaginationState,
|
|
TableOptions,
|
|
flexRender,
|
|
getCoreRowModel,
|
|
useReactTable,
|
|
} from "@tanstack/react-table";
|
|
import { SetStateAction, useMemo, useState } from "react";
|
|
import { FiArrowRight } from "react-icons/fi";
|
|
import { Button, Card, Text } from "tw-components";
|
|
|
|
type TWTableProps<TRowData> = {
|
|
columns: ColumnDef<TRowData, any>[];
|
|
data: TRowData[];
|
|
isLoading: boolean;
|
|
isFetched: boolean;
|
|
onRowClick?: (row: TRowData) => void;
|
|
pagination?: {
|
|
pageSize: number;
|
|
};
|
|
showMore?: {
|
|
pageSize: number;
|
|
showLess?: boolean;
|
|
};
|
|
};
|
|
|
|
export function TWTable<TRowData>(tableProps: TWTableProps<TRowData>) {
|
|
const [showMoreLimit, setShowMoreLimit] = useState(
|
|
tableProps.showMore?.pageSize || Infinity,
|
|
);
|
|
const [{ pageIndex, pageSize }, setPagination] = useState<PaginationState>({
|
|
pageIndex: 0,
|
|
pageSize: tableProps.pagination?.pageSize || 25,
|
|
});
|
|
|
|
const slicedData = useMemo(() => {
|
|
if (tableProps.showMore) {
|
|
return tableProps.data.slice(0, showMoreLimit || Infinity);
|
|
}
|
|
if (tableProps.pagination) {
|
|
return tableProps.data.slice(
|
|
pageIndex * pageSize,
|
|
pageIndex * pageSize + pageSize,
|
|
);
|
|
}
|
|
return tableProps.data;
|
|
}, [
|
|
tableProps.showMore,
|
|
tableProps.pagination,
|
|
tableProps.data,
|
|
showMoreLimit,
|
|
pageIndex,
|
|
pageSize,
|
|
]);
|
|
|
|
const pagination = useMemo(
|
|
() => ({
|
|
pageIndex,
|
|
pageSize,
|
|
}),
|
|
[pageIndex, pageSize],
|
|
);
|
|
|
|
const paginationOptions: Pick<
|
|
TableOptions<TRowData>,
|
|
"state" | "onPaginationChange" | "manualPagination" | "pageCount"
|
|
> = useMemo(
|
|
() =>
|
|
tableProps.pagination
|
|
? {
|
|
pageCount: Math.ceil(slicedData.length / pageSize),
|
|
state: { pagination },
|
|
onPaginationChange: setPagination,
|
|
manualPagination: true,
|
|
}
|
|
: {},
|
|
[pageSize, pagination, slicedData.length, tableProps.pagination],
|
|
);
|
|
|
|
const table = useReactTable({
|
|
data: slicedData,
|
|
columns: tableProps.columns,
|
|
...paginationOptions,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
// TODO - add filtering?
|
|
// getFilteredRowModel: getFilteredRowModel(),
|
|
});
|
|
|
|
return (
|
|
<Card p={0} overflowX="auto" position="relative" overflowY="hidden">
|
|
<Table
|
|
bg="backgroundHighlight"
|
|
p={4}
|
|
borderTopRadius="lg"
|
|
overflow="hidden"
|
|
>
|
|
<Thead bg="blackAlpha.50" _dark={{ bg: "whiteAlpha.50" }}>
|
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
<Tr key={headerGroup.id}>
|
|
{headerGroup.headers.map((header) => (
|
|
<Th
|
|
key={header.id}
|
|
colSpan={header.colSpan}
|
|
borderBottomColor="borderColor"
|
|
>
|
|
{header.isPlaceholder ? null : (
|
|
<Flex align="center" gap={2}>
|
|
<Text as="label" size="label.md">
|
|
{flexRender(
|
|
header.column.columnDef.header,
|
|
header.getContext(),
|
|
)}
|
|
</Text>
|
|
{/* TODO add fitlering? */}
|
|
{/* {header.column.getCanFilter() ? (
|
|
<div>
|
|
<Filter column={header.column} table={table} />
|
|
</div>
|
|
) : null} */}
|
|
</Flex>
|
|
)}
|
|
</Th>
|
|
))}
|
|
{/* if the row is clickable we want an arrow to show */}
|
|
{tableProps.onRowClick && <Th borderBottomColor="borderColor" />}
|
|
</Tr>
|
|
))}
|
|
</Thead>
|
|
|
|
<Tbody>
|
|
{table.getRowModel().rows.map((row) => {
|
|
return (
|
|
<Tr
|
|
key={row.id}
|
|
role="group"
|
|
borderBottomWidth={1}
|
|
_last={{ borderBottomWidth: 0 }}
|
|
{...(tableProps.onRowClick
|
|
? {
|
|
style: {
|
|
cursor: "pointer",
|
|
},
|
|
onClick: () => tableProps.onRowClick?.(row.original),
|
|
_hover: { bg: "blackAlpha.50" },
|
|
_dark: {
|
|
_hover: {
|
|
bg: "whiteAlpha.50",
|
|
},
|
|
},
|
|
}
|
|
: {})}
|
|
>
|
|
{row.getVisibleCells().map((cell) => {
|
|
return (
|
|
<Td
|
|
key={cell.id}
|
|
borderBottomWidth="inherit"
|
|
borderBottomColor="borderColor"
|
|
>
|
|
{flexRender(
|
|
cell.column.columnDef.cell,
|
|
cell.getContext(),
|
|
)}
|
|
</Td>
|
|
);
|
|
})}
|
|
{/* if the row is clickable we want an arrow to show */}
|
|
{tableProps.onRowClick && (
|
|
<Td
|
|
isNumeric
|
|
borderBottomWidth="inherit"
|
|
borderBottomColor="borderColor"
|
|
>
|
|
<Icon as={FiArrowRight} />
|
|
</Td>
|
|
)}
|
|
</Tr>
|
|
);
|
|
})}
|
|
</Tbody>
|
|
</Table>
|
|
{tableProps.isLoading && (
|
|
<Center>
|
|
<Flex py={4} direction="row" gap={4} align="center">
|
|
<Spinner size="sm" />
|
|
<Text>Loading programs</Text>
|
|
</Flex>
|
|
</Center>
|
|
)}
|
|
{tableProps.data.length === 0 && tableProps.isFetched && (
|
|
<Center>
|
|
<Flex py={4} direction="column" gap={4} align="center">
|
|
<Text>No programs found.</Text>
|
|
</Flex>
|
|
</Center>
|
|
)}
|
|
<ShowMoreButton
|
|
shouldShowMore={slicedData.length < tableProps.data.length}
|
|
shouldShowLess={
|
|
!!tableProps.showMore?.showLess &&
|
|
slicedData.length > tableProps.showMore.pageSize
|
|
}
|
|
pageSize={tableProps.showMore?.pageSize || -1}
|
|
showMoreLimit={showMoreLimit}
|
|
setShowMoreLimit={setShowMoreLimit}
|
|
/>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
interface ShowMoreButtonProps {
|
|
pageSize: number;
|
|
showMoreLimit: number;
|
|
setShowMoreLimit: (value: SetStateAction<number>) => void;
|
|
shouldShowMore: boolean;
|
|
shouldShowLess: boolean;
|
|
}
|
|
|
|
const ShowMoreButton: React.FC<ShowMoreButtonProps> = ({
|
|
pageSize,
|
|
showMoreLimit,
|
|
setShowMoreLimit,
|
|
shouldShowLess,
|
|
shouldShowMore,
|
|
}) => {
|
|
if (!shouldShowMore && !shouldShowLess) {
|
|
return null;
|
|
}
|
|
let newShowLess = showMoreLimit - pageSize;
|
|
if (newShowLess < pageSize) {
|
|
newShowLess = pageSize;
|
|
}
|
|
|
|
return (
|
|
<Flex flexDir="column">
|
|
<Divider color="borderColor" />
|
|
<Center>
|
|
<ButtonGroup variant="ghost" size="sm" py={2}>
|
|
{shouldShowMore && (
|
|
<Button onClick={() => setShowMoreLimit(showMoreLimit + pageSize)}>
|
|
Show more
|
|
</Button>
|
|
)}
|
|
{shouldShowLess && (
|
|
<Button onClick={() => setShowMoreLimit(newShowLess)}>
|
|
Show Less
|
|
</Button>
|
|
)}
|
|
</ButtonGroup>
|
|
</Center>
|
|
</Flex>
|
|
);
|
|
};
|