Newer
Older
taehui / qwilight-fe / src / note / useGetComment.ts
@Taehui Taehui on 12 Mar 839 bytes 2024-03-12 오후 7:02
import { useQuery } from "@tanstack/react-query";
import { getLanguage } from "taehui-ts/language";

import { useSiteStore } from "src/Stores";
import { wwwAXIOS } from "src/Www";
import { GetCommentAPI } from "src/wwwAPI";

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 wwwAXIOS.get<GetCommentAPI>("/comment", {
        params: {
          noteID,
          avatarID: siteAvatarID,
          language,
        },
      });

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