import { useAuth } from "@web/src/providers/auth-provider"; import { useStaff } from "@nice/client"; import { useContext, useState } from "react"; import { useNavigate } from "react-router-dom"; import { CourseDetailContext } from "../PostDetailContext"; import toast from "react-hot-toast"; import { CheckCircleOutlined, CloseCircleOutlined, LoginOutlined, } from "@ant-design/icons"; export default function JoinButton() { const { isAuthenticated, user } = useAuth(); const navigate = useNavigate(); const { post, canEdit, userIsLearning, setUserIsLearning } = useContext(CourseDetailContext); const { update } = useStaff(); const [isHovered, setIsHovered] = useState(false); const toggleLearning = async () => { if (!userIsLearning) { await update.mutateAsync({ where: { id: user?.id }, data: { learningPosts: { connect: { id: post.id }, }, }, }); setUserIsLearning(true); toast.success("加入学习成功"); } else { await update.mutateAsync({ where: { id: user?.id }, data: { learningPosts: { disconnect: { id: post.id, }, }, }, }); toast.success("退出学习成功"); setUserIsLearning(false); } }; return ( <> {isAuthenticated && (