Newer
Older
taehui / qwilight-fe / src / app / [language] / hall / query / useGetAtTopHall.ts
@Taehui Taehui on 20 Apr 961 bytes 2024-04-20 오후 2:05
import { Hall } from "@/app/[language]/hall/type";
import { useHallStore } from "@/state/Stores";
import { GetHallAPI } from "@/type/wwwAPI";
import { formatText } from "@/utilities/Utility";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useTranslations } from "next-intl";
import { useIsPath } from "taehui-lib/fe-utilities";

export default function useGetAtTopHall() {
  const { tabItem, atTabItem } = useHallStore();

  const t = useTranslations();

  const isPath = useIsPath();

  return useQuery<Hall[]>({
    enabled: tabItem === "at" && atTabItem === "top" && isPath("/hall"),
    queryKey: ["atTopHall"],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetHallAPI[]>("/hall/atTop");
      return data.map((hall) => ({
        ...hall,
        value: hall.value,
        text: t("textCount", { value: formatText(hall.value) }),
      }));
    },
    initialData: [],
  });
}