Newer
Older
taehui / qwilight-fe / src / hof / useGetAtStandHOF.ts
@Taehui Taehui on 16 Mar 936 bytes 2024-03-17 오전 2:53
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 { useIsPath } from "taehui-ts/fe-utility";

export default function useGetAtStandHOF() {
  const { tabPosition, atTabPosition } = useHOFStore();

  const t = useTranslations();

  const isPath = useIsPath();

  return useQuery<
    {
      avatarID: string;
      avatarName: string;
      text: string;
    }[]
  >({
    enabled: tabPosition === 1 && atTabPosition === 2 && isPath("/hof"),
    queryKey: ["atStandHOF"],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetHOFAPI[]>("/hof/atStand");
      return data.map((hof) => ({
        ...hof,
        text: t("textStand", { value: formatText(hof.value) }),
      }));
    },
    initialData: [],
  });
}