diff --git a/src/components/Cards/GameItemCard.tsx b/src/components/Cards/GameItemCard.tsx new file mode 100644 index 0000000..b887743 --- /dev/null +++ b/src/components/Cards/GameItemCard.tsx @@ -0,0 +1,49 @@ +import { FC } from "react"; +import { Card } from "./Card"; +import cn from "classnames"; +import Skeleton from "react-loading-skeleton"; + +export type GameItemCardProps = Partial<{ + name: string; + content: string; + compact: boolean; +}>; + +export const GameItemCard: FC = ({ + name, + content, + compact, +}) => { + return ( + +
+
+ {name ?? } +
+
+ {content ?? } +
+
+
+ ); +}; diff --git a/src/hooks/useLatestGame.ts b/src/hooks/useLatestGame.ts index 0cda8a0..84a0389 100644 --- a/src/hooks/useLatestGame.ts +++ b/src/hooks/useLatestGame.ts @@ -6,29 +6,31 @@ import { useEffect, useState } from "react"; const url = "/index/indexes/disputegames/search"; type GamesParams = { - limit?: string, - offset?: string, - sort?: any -} + limit?: string; + offset?: string; + sort?: any; + q?: string; +}; const defaultParams: GamesParams = { - limit: '5', - offset: '0', + limit: "5", + offset: "0", sort: ["block_number:desc"], }; - const getFetcher = (u: string) => { return async (): Promise> => { return await get(u); }; -} +}; -export const useLatestGame = (params?: GamesParams): SWRResponse, Error, boolean> => { +export const useLatestGame = ( + params?: GamesParams +): SWRResponse, Error, boolean> => { const p = { ...defaultParams, - ... (params ? params : {}) - } + ...(params ? params : {}), + }; const queryString = new URLSearchParams(p); const requestUrl = `${url}?${queryString.toString()}`; const res = useSWR(requestUrl, getFetcher(requestUrl)); diff --git a/src/pages/game/[game].tsx b/src/pages/game/[game].tsx index f47cf72..6738b8b 100644 --- a/src/pages/game/[game].tsx +++ b/src/pages/game/[game].tsx @@ -2,21 +2,65 @@ import { useRouter } from "next/router"; import React, { useMemo } from "react"; import ClaimChart from "@/components/Charts/ClaimChart"; import { useClaimData } from "@/hooks/useClaimData"; +import { ChartSkeleton } from "@/components/ChartSkeleton"; +import { ClaimData } from "@/types"; +import { useLatestGame } from "@/hooks/useLatestGame"; +import { GameItemCard } from "@/components/Cards/GameItemCard"; +import Skeleton from "react-loading-skeleton"; +import { shortenAddress } from "@/utils"; +import { + formatSeconds, + formatTimestamp, + formatTtl, + getHumanDate, +} from "@/utils/date"; const GameDetail = () => { const router = useRouter(); - console.log(router); const address = (router.query.game as string | undefined) ?? ""; - console.log(address); const { data, isLoading } = useClaimData(address); - if (!data) { - return <>no data; - } - + const { data: game, isLoading: gameLoading } = useLatestGame({ + limit: "1", + q: address, + }); return ( -
- +
+ {gameLoading && isLoading ? ( + + ) : ( +
+ + + + + + +
+ )} + + {isLoading ? ( +
+ +
+ ) : ( + + )}
); }; diff --git a/src/utils/date.ts b/src/utils/date.ts index 0b8c595..9f9d39f 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -36,3 +36,8 @@ export function formatTtl(ttl: number) { export function getHumanDate(date: string | Date) { return dayjs(date).format("dddd, MMMM, DD YYYY"); } + +export function formatSeconds(secs: number) { + const date = new Date(secs * 1000); + return dayjs(date).format("YYYY/MM/DD hh:mm:ss"); +}