Newer
Older
taehui / qwilight-fe / src / hall / useGetAbility5KHall.ts
@Taehui Taehui on 16 Mar 871 bytes 2024-03-17 오전 8:09
import { useHallStore } from "@/Stores";
import { formatText } from "@/Utility";

import { wwwAXIOS } from "@/Www";
import { GetHallAPI } from "@/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useIsPath } from "taehui-ts/fe-utility";

export default function useGetAbility5KHall() {
  const { tabPosition, abilityTabPosition } = useHallStore();

  const isPath = useIsPath();

  return useQuery<
    {
      avatarID: string;
      avatarName: string;
      text: string;
    }[]
  >({
    enabled: tabPosition === 2 && abilityTabPosition === 0 && isPath("/hall"),
    queryKey: ["ability5KHall"],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetHallAPI[]>("/hall/ability/5K");
      return data.map((hall) => ({
        ...hall,
        text: `${formatText(hall.value)} Point`,
      }));
    },
    initialData: [],
  });
}