import { useMutation, useQueryClient } from "@tanstack/react-query";

import { wwwAXIOS } from "src/Www";

export default function usePostCommentary() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: async ({
      avatarName,
      avatarCipher,
      text,
    }: {
      avatarName: string;
      avatarCipher: string;
      text: string;
    }) => {
      await wwwAXIOS.post("/commentary", {
        avatarName,
        avatarCipher,
        text,
      });
    },
    onSuccess: async () => {
      await queryClient.invalidateQueries({ queryKey: ["commentary"] });
    },
  });
}
