Skip to content

Commit 6b78ad6

Browse files
committed
feat: pages for activity
1 parent 724c7e7 commit 6b78ad6

File tree

1 file changed

+65
-27
lines changed

1 file changed

+65
-27
lines changed

apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/components/ActivityOverview.tsx

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ export function ActivityOverview({
4040
contracts,
4141
isLoading,
4242
}: ActivityOverviewProps) {
43-
const [activeTab, setActiveTab] = useState<"transactions" | "contracts">(
44-
"transactions",
45-
);
43+
const [activeTab, setActiveTab] = useState<"transactions" | "contracts">("transactions");
44+
const [currentPage, setCurrentPage] = useState(1);
45+
const itemsPerPage = 5;
46+
47+
// Calculate the index of the last transaction on the current page
48+
const lastIndex = currentPage * itemsPerPage;
49+
// Calculate the index of the first transaction on the current page
50+
const firstIndex = lastIndex - itemsPerPage;
51+
// Get the current transactions to display
52+
const currentTransactions = transactions.slice(firstIndex, lastIndex);
53+
// Calculate total pages
54+
const totalPages = Math.ceil(transactions.length / itemsPerPage);
4655

4756
return (
4857
<Card>
@@ -71,31 +80,60 @@ export function ActivityOverview({
7180
{isLoading ? (
7281
<Spinner />
7382
) : activeTab === "transactions" ? (
74-
<Table>
75-
<TableHeader>
76-
<TableRow>
77-
{/* <TableHead>Type</TableHead> */}
78-
<TableHead>Amount</TableHead>
79-
<TableHead>Details</TableHead>
80-
<TableHead>Date</TableHead>
81-
</TableRow>
82-
</TableHeader>
83-
<TableBody>
84-
{transactions.map((tx) => (
85-
<TableRow key={tx.id}>
86-
{/* <TableCell>{tx.type}</TableCell> */}
87-
<TableCell>{tx.amount}</TableCell>
88-
<TableCell>
89-
{tx.to && `To: ${tx.to} `}
90-
{tx.from && `From: ${tx.from} `}
91-
{tx.contract && `Contract: ${tx.contract} `}
92-
{tx.method && ` Method: ${tx.method}`}
93-
</TableCell>
94-
<TableCell>{tx.date}</TableCell>
83+
<>
84+
<Table>
85+
<TableHeader>
86+
<TableRow>
87+
{/* <TableHead>Type</TableHead> */}
88+
<TableHead>Amount</TableHead>
89+
<TableHead>Details</TableHead>
90+
<TableHead>Date</TableHead>
9591
</TableRow>
96-
))}
97-
</TableBody>
98-
</Table>
92+
</TableHeader>
93+
<TableBody>
94+
{currentTransactions.map((tx) => (
95+
<TableRow key={tx.id}>
96+
{/* <TableCell>{tx.type}</TableCell> */}
97+
<TableCell>{tx.amount}</TableCell>
98+
<TableCell>
99+
{tx.to && `To: ${tx.to} `}
100+
{tx.from && `From: ${tx.from} `}
101+
{tx.contract && `Contract: ${tx.contract} `}
102+
{tx.method && ` Method: ${tx.method}`}
103+
</TableCell>
104+
<TableCell>{tx.date}</TableCell>
105+
</TableRow>
106+
))}
107+
</TableBody>
108+
</Table>
109+
110+
{/* Pagination Controls */}
111+
<div className="pagination">
112+
<TabButtons
113+
tabs={[
114+
{
115+
name: "Previous",
116+
isActive: currentPage === 1,
117+
isEnabled: currentPage > 1,
118+
onClick: () => setCurrentPage((prev) => Math.max(prev - 1, 1)),
119+
},
120+
{
121+
name: `Page ${currentPage} of ${totalPages}`,
122+
isActive: true,
123+
isEnabled: false,
124+
onClick: () => {}, // No action needed
125+
},
126+
{
127+
name: "Next",
128+
isActive: currentPage === totalPages,
129+
isEnabled: currentPage < totalPages,
130+
onClick: () => setCurrentPage((prev) => Math.min(prev + 1, totalPages)),
131+
},
132+
]}
133+
tabClassName="font-medium !text-sm"
134+
/>
135+
</div>
136+
</>
99137
) : activeTab === "contracts" ? (
100138
<Table>
101139
<TableHeader>

0 commit comments

Comments
 (0)