Newer
Older
taehui / qwilight-fe / src / hof / useGetTotalHighestHOF.ts
@Taehui Taehui on 16 Mar 1 KB 2024-03-17 오전 1:28
import { useQuery } from "@tanstack/react-query";
import { useLocation } from "react-router-dom";
import { sprintf } from "sprintf-js";

import { wwwAXIOS } from "@/Www";
import { GetHOFAPI } from "@/wwwAPI";
import { useHOFStore } from "@/Stores";
import { formatText } from "@/Utility";
import { useTranslations } from "next-intl";

export default function useGetTotalHighestHOF() {
  const { tabPosition, totalTabPosition } = useHOFStore();

  const t = useTranslations();

  const { pathname } = useLocation();

  return useQuery<
    {
      avatarID: string;
      avatarName: string;
      text: string;
    }[]
  >({
    enabled:
      tabPosition === 0 &&
      totalTabPosition === 1 &&
      pathname.startsWith("/hof"),
    queryKey: ["totalHighestHOF"],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetHOFAPI[]>("/hof/totalHighest");
      return data.map((hof) => ({
        ...hof,
        text: sprintf(t("textCount"), formatText(hof.value)),
      }));
    },
    initialData: [],
  });
}