Newer
Older
taehui / qwilight-fe / src / app / [language] / note / query / useGetComment.ts
@Taehui Taehui on 17 Mar 852 bytes 2024-03-17 오후 3:50
import { useSiteStore } from "@/state/Stores";
import { GetCommentAPI } from "@/type/wwwAPI";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { getLanguage } from "taehui-ts/language";

export default function useGetComment(
  noteID: string,
  isCommentOpened: boolean,
) {
  const { siteAvatarID } = useSiteStore();

  const language = getLanguage();
  return useQuery({
    enabled: isCommentOpened,
    queryKey: ["comment", noteID, siteAvatarID, language],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetCommentAPI>("/comment", {
        params: {
          noteID,
          avatarID: siteAvatarID,
          language,
        },
      });

      return data;
    },
    initialData: {
      comments: [],
      commentPlace: -1,
      totalComments: 0,
    },
  });
}