From 5dd98693197bffc56fb1d0370e6d717c93ba7ff4 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Sun, 17 Dec 2023 23:11:04 -0500 Subject: [PATCH] Create table skeleton --- src/app/staking/page.tsx | 6 +- .../validators/ValidatorGroupTable.tsx | 71 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/features/validators/ValidatorGroupTable.tsx diff --git a/src/app/staking/page.tsx b/src/app/staking/page.tsx index f18291e..d7bfc66 100644 --- a/src/app/staking/page.tsx +++ b/src/app/staking/page.tsx @@ -4,6 +4,7 @@ import { SolidButton } from 'src/components/buttons/SolidButton'; import { Card } from 'src/components/layout/Card'; import { Section } from 'src/components/layout/Section'; import { Amount } from 'src/components/numbers/Amount'; +import { ValidatorGroupTable } from 'src/features/validators/ValidatorGroupTable'; import { useValidatorGroups } from 'src/features/validators/hooks'; import { ValidatorGroup, ValidatorStatus } from 'src/features/validators/types'; import { bigIntMin } from 'src/utils/math'; @@ -76,9 +77,10 @@ function ListSection({ groups }: { groups?: ValidatorGroup[] }) { return (
-
+ + {/*
{groups?.map((g) =>
{JSON.stringify(g)}
)} -
+
*/}
); diff --git a/src/features/validators/ValidatorGroupTable.tsx b/src/features/validators/ValidatorGroupTable.tsx new file mode 100644 index 0000000..72911a9 --- /dev/null +++ b/src/features/validators/ValidatorGroupTable.tsx @@ -0,0 +1,71 @@ +import { + SortingState, + createColumnHelper, + flexRender, + getCoreRowModel, + getSortedRowModel, + useReactTable, +} from '@tanstack/react-table'; +import { useMemo, useState } from 'react'; +import { config } from 'src/config/config'; +import { ValidatorGroup } from './types'; + +export function ValidatorGroupTable({ groups }: { groups: ValidatorGroup[] }) { + const [sorting, setSorting] = useState([]); + + const columns = useMemo(() => { + const columnHelper = createColumnHelper(); + return [ + columnHelper.accessor('name', { + header: 'Name', + cell: (props) => {props.getValue().toUpperCase()}, + }), + columnHelper.accessor('address', { + header: 'Status', + }), + columnHelper.display({ + id: 'cumulativeShare', + cell: () =>
, + }), + ]; + }, []); + + const table = useReactTable({ + data: groups, + columns, + state: { + sorting, + }, + onSortingChange: setSorting, + getCoreRowModel: getCoreRowModel(), + getSortedRowModel: getSortedRowModel(), + debugTable: config.debug, + }); + + return ( + + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + ))} + + ))} + + + {table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + ))} + + ))} + +
+ {header.isPlaceholder + ? null + : flexRender(header.column.columnDef.header, header.getContext())} +
{flexRender(cell.column.columnDef.cell, cell.getContext())}
+ ); +}