From 55a61a4d569895e20231b092eb4f4f462868343c Mon Sep 17 00:00:00 2001 From: TwilightLogic Date: Fri, 19 Apr 2024 14:31:14 +0800 Subject: [PATCH] feat: add pagination logic and component --- .../assets-details/tabs/coin/assets-coin.tsx | 157 +++++++++++------- 1 file changed, 98 insertions(+), 59 deletions(-) diff --git a/rooch-portal-v1/src/pages/assets/assets-details/tabs/coin/assets-coin.tsx b/rooch-portal-v1/src/pages/assets/assets-details/tabs/coin/assets-coin.tsx index 75fa68d104..188bb45091 100644 --- a/rooch-portal-v1/src/pages/assets/assets-details/tabs/coin/assets-coin.tsx +++ b/rooch-portal-v1/src/pages/assets/assets-details/tabs/coin/assets-coin.tsx @@ -2,7 +2,6 @@ import { Table, TableBody, TableCell, - TableFooter, TableHead, TableHeader, TableRow, @@ -17,10 +16,19 @@ import { DropdownMenuShortcut, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' +import { + Pagination, + PaginationContent, + PaginationItem, + PaginationLink, + PaginationNext, + PaginationPrevious, +} from '@/components/ui/pagination' import { NoData } from '@/components/no-data' import { Button } from '@/components/ui/button' import { GripVerticalIcon } from 'lucide-react' +import { useState } from 'react' interface Coin { coin: string @@ -29,19 +37,25 @@ interface Coin { } const coins: Coin[] = [ - // { - // coin: 'ROOCH', - // balance: 288.88, - // value: '$1,146.98', - // }, - { - coin: '', - balance: 0, - value: '', - }, + { coin: 'ROOCH', balance: 288.88, value: '$1,146.98' }, + { coin: 'BTC', balance: 2.5, value: '$95,000.00' }, + { coin: 'ETH', balance: 10, value: '$30,000.00' }, + { coin: 'LTC', balance: 100, value: '$10,000.00' }, + { coin: 'XRP', balance: 2000, value: '$1,200.00' }, + { coin: 'DOGE', balance: 15000, value: '$4,500.00' }, ] export const AssetsCoin = () => { + const [currentPage, setCurrentPage] = useState(0) + const itemsPerPage = 5 + + const pageCount = Math.ceil(coins.length / itemsPerPage) + const currentItems = coins.slice(currentPage * itemsPerPage, (currentPage + 1) * itemsPerPage) + + const handlePageChange = (selectedPage: number) => { + setCurrentPage(selectedPage) + } + const hasValidData = (coins: Coin[]): boolean => { return coins.some((coin) => coin.coin.trim() !== '' && coin.balance !== 0) } @@ -51,55 +65,80 @@ export const AssetsCoin = () => { } return ( -
- - - - Asset - Balance - Value - Action - - - - {coins.map((coin) => ( - - {coin.coin} - {coin.balance} - {coin.value} - - - - - - - Action - - - {}}> - Transfer - ⇧⌘F - - {}}> - Swap - ⇧⌘S - - - - - + <> +
+
+ + + Asset + Balance + Value + Action + + + {currentItems.map((coin) => ( + + {coin.coin} + {coin.balance} + {coin.value} + + + + + + + Action + + + {}}> + Transfer + ⇧⌘F + + {}}> + Swap + ⇧⌘S + + + + + + + ))} + +
+
+ + + + handlePageChange(Math.max(0, currentPage - 1))} + /> + + {Array.from({ length: pageCount }, (_, index) => ( + + handlePageChange(index)} + isActive={index === currentPage} + > + {index + 1} + + ))} - - - - Total - $25,000.00 - - - - + {currentPage < pageCount - 1 && ( + + handlePageChange(Math.min(pageCount - 1, currentPage + 1))} + /> + + )} + + + ) }