"use client" import { useEffect, useState } from "react" import { trpc } from "@/lib/trpc/client" import { ChevronRightIcon } from "@/components/Icons" import DesktopTable from "./Desktop" import MobileTable from "./Mobile" import styles from "../earnAndBurn.module.css" import { Transactions } from "@/types/components/myPages/myPage/earnAndBurn" function PaginationButton({ children, isActive, handleClick, disabled, }: React.PropsWithChildren<{ disabled: boolean isActive?: boolean handleClick: () => void }>) { return ( ) } function Pagination({ pageCount, isFetching, handlePageChange, currentPage, }: { pageCount: number isFetching: boolean handlePageChange: (page: number) => void currentPage: number }) { const isOnFirstPage = currentPage === 1 const isOnLastPage = currentPage === pageCount return (
{ handlePageChange(currentPage - 1) }} > {[...Array(pageCount)].map((_, idx) => ( { handlePageChange(idx + 1) }} > {idx + 1} ))} { handlePageChange(currentPage + 1) }} >
) } export default function TransactionTable() { const limit = 5 const [page, setPage] = useState(1) const [totalPages, setTotalPages] = useState(0) const [currentTransactions, setCurrentTransactions] = useState( [] ) const { data, isFetching, isLoading } = trpc.user.transaction.friendTransactions.useQuery({ limit, page, }) // Should the active page be mirroried in the URL with params? // That way the actual fetch could be moved up and Mobile/Desktop can be strictly server side useEffect(() => { if (typeof data?.data.pages === "number") { setTotalPages(data?.data.pages) } }, [data?.data.pages]) useEffect(() => { if (data?.data.transactions) { setCurrentTransactions(data.data.transactions) } }, [data?.data.transactions]) return !currentTransactions.length ? ( "Loading..." // Add loading state table ) : ( <> {totalPages > 1 ? ( ) : null} ) }