Newer
Older
taehui / qwilight-fe / src / app / [language] / hall / query / useGetLevelHall.ts
@Taehui Taehui on 18 Mar 746 bytes v1.0.0
import { Hall } from "@/app/[language]/hall/type";
import { useHallStore } from "@/state/Stores";
import { GetHallAPI } from "@/type/wwwAPI";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useIsPath } from "taehui-ts/fe-utilities";

export default function useGetLevelHall() {
  const { tabPosition } = useHallStore();

  const isPath = useIsPath();

  return useQuery<Hall[]>({
    enabled: tabPosition === 3 && isPath("/hall"),
    queryKey: ["levelHall"],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetHallAPI[]>("/hall/level");
      return data.map((hall) => ({
        ...hall,
        text: `LV.${hall.value}`,
      }));
    },
    initialData: [],
  });
}