Newer
Older
taehui / qwilight-fe / src / hof / useGetTotalBandHOF.ts
@Taehui Taehui on 16 Mar 983 bytes 2024-03-17 오전 2:07
import { useHOFStore } from "@/Stores";
import { formatText } from "@/Utility";

import { wwwAXIOS } from "@/Www";
import { GetHOFAPI } from "@/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useTranslations } from "next-intl";
import { sprintf } from "sprintf-js";
import { useIsPath } from "taehui-ts/fe-utility";

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

  const t = useTranslations();

  const isPath = useIsPath();

  return useQuery<
    {
      avatarID: string;
      avatarName: string;
      text: string;
    }[]
  >({
    enabled: tabPosition === 0 && totalTabPosition === 3 && isPath("/hof"),
    queryKey: ["totalBandHOF"],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetHOFAPI[]>("/hof/totalBand");
      return data.map((hof) => ({
        ...hof,
        text: sprintf(t("textBand"), formatText(hof.value)),
      }));
    },
    initialData: [],
  });
}