diff --git a/components/MyPages/Blocks/Points/EarnAndBurn/JourneyTable/Client.tsx b/components/MyPages/Blocks/Points/EarnAndBurn/JourneyTable/Client.tsx new file mode 100644 index 000000000..e4905270f --- /dev/null +++ b/components/MyPages/Blocks/Points/EarnAndBurn/JourneyTable/Client.tsx @@ -0,0 +1,132 @@ +"use client" + +import { useEffect, useState } from "react" + +import { trpc } from "@/lib/trpc/client" + +import { ChevronRightIcon } from "@/components/Icons" +import LoadingSpinner from "@/components/LoadingSpinner" + +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({ + initialJourneyTransactions, +}: { + initialJourneyTransactions: { + data: { transactions: Transactions } + meta: { totalPages: number } + } +}) { + const limit = 5 + const [page, setPage] = useState(1) + // const [currentTransactions, setCurrentTransactions] = useState( + // [] + // ) + const { data, isFetching, isLoading } = + trpc.user.transaction.friendTransactions.useQuery( + { + limit, + page, + }, + { + initialData: initialJourneyTransactions, + } + ) + + // useEffect(() => { + // if (data?.data.transactions) { + // setCurrentTransactions(data.data.transactions) + // } + // }, [data?.data.transactions]) + // const totalPages = data?.meta.totalPages || 0 + return isLoading ? ( + + ) : ( + <> + + + {data && data.meta.totalPages > 1 ? ( + + ) : null} + + ) +} diff --git a/components/MyPages/Blocks/Points/EarnAndBurn/JourneyTable/index.tsx b/components/MyPages/Blocks/Points/EarnAndBurn/JourneyTable/index.tsx index 71c624dd6..1a7922669 100644 --- a/components/MyPages/Blocks/Points/EarnAndBurn/JourneyTable/index.tsx +++ b/components/MyPages/Blocks/Points/EarnAndBurn/JourneyTable/index.tsx @@ -1,124 +1,18 @@ -"use client" +import { serverClient } from "@/lib/trpc/server" -import { useEffect, useState } from "react" +import ClientJourney from "./Client" -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, +export default async function JourneyTable() { + const initialJourneyTransactions = + await serverClient().user.transaction.friendTransactions({ + page: 1, + limit: 5, }) - useEffect(() => { - if (typeof data?.meta.totalPages === "number") { - setTotalPages(data?.meta.totalPages) - } - }, [data?.meta.totalPages]) + if (!initialJourneyTransactions?.data.transactions.length) { + return null + } - useEffect(() => { - if (data?.data.transactions) { - setCurrentTransactions(data.data.transactions) - } - }, [data?.data.transactions]) - - return !currentTransactions.length ? ( - "Loading..." // Add loading state table - ) : ( - <> - - - {totalPages > 1 ? ( - - ) : null} - + return ( + ) } diff --git a/components/MyPages/Blocks/Points/EarnAndBurn/index.tsx b/components/MyPages/Blocks/Points/EarnAndBurn/index.tsx index 3eb3d5496..83a325a04 100644 --- a/components/MyPages/Blocks/Points/EarnAndBurn/index.tsx +++ b/components/MyPages/Blocks/Points/EarnAndBurn/index.tsx @@ -1,5 +1,3 @@ -import { serverClient } from "@/lib/trpc/server" - import SectionContainer from "@/components/Section/Container" import SectionHeader from "@/components/Section/Header" import SectionLink from "@/components/Section/Link" @@ -13,14 +11,6 @@ export default async function EarnAndBurn({ subtitle, title, }: AccountPageComponentProps) { - const transactionsData = - await serverClient().user.transaction.friendTransactions({ - limit: 10, - page: 1, - }) - if (!transactionsData) { - return null - } return ( diff --git a/server/routers/user/query.ts b/server/routers/user/query.ts index a42b8ea1f..7f04257de 100644 --- a/server/routers/user/query.ts +++ b/server/routers/user/query.ts @@ -459,6 +459,7 @@ export const userQueryRouter = router({ .query(async ({ ctx, input }) => { const { limit, page } = input const apiResponse = await api.get(api.endpoints.v1.friendTransactions, { + cache: undefined, // override defaultOptions headers: { Authorization: `Bearer ${ctx.session.token.access_token}`, },