Skip to content

Commit

Permalink
Create table skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Dec 18, 2023
1 parent 4c5104c commit 5dd9869
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app/staking/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -76,9 +77,10 @@ function ListSection({ groups }: { groups?: ValidatorGroup[] }) {
return (
<Section>
<Card>
<div className="space-y-4">
<ValidatorGroupTable groups={groups || []} />
{/* <div className="space-y-4">
{groups?.map((g) => <div key={g.address}>{JSON.stringify(g)}</div>)}
</div>
</div> */}
</Card>
</Section>
);
Expand Down
71 changes: 71 additions & 0 deletions src/features/validators/ValidatorGroupTable.tsx
Original file line number Diff line number Diff line change
@@ -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<SortingState>([]);

const columns = useMemo(() => {
const columnHelper = createColumnHelper<ValidatorGroup>();
return [
columnHelper.accessor('name', {
header: 'Name',
cell: (props) => <span>{props.getValue().toUpperCase()}</span>,
}),
columnHelper.accessor('address', {
header: 'Status',
}),
columnHelper.display({
id: 'cumulativeShare',
cell: () => <div className="bg-purple w-2"></div>,
}),
];
}, []);

const table = useReactTable<ValidatorGroup>({
data: groups,
columns,
state: {
sorting,
},
onSortingChange: setSorting,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
debugTable: config.debug,
});

return (
<table>
<thead>
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<th key={header.id}>
{header.isPlaceholder
? null
: flexRender(header.column.columnDef.header, header.getContext())}
</th>
))}
</tr>
))}
</thead>
<tbody>
{table.getRowModel().rows.map((row) => (
<tr key={row.id}>
{row.getVisibleCells().map((cell) => (
<td key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</td>
))}
</tr>
))}
</tbody>
</table>
);
}

0 comments on commit 5dd9869

Please sign in to comment.