"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { MessageSquare } from "lucide-react"; import { apiOpenDirectChat } from "@/lib/api"; import { toast } from "@/lib/toast"; /** 用户主页:发起私聊 */ export default function StartDMButton({ userId }: { userId: number }) { const router = useRouter(); const [loading, setLoading] = useState(false); const start = async () => { setLoading(true); try { const { room } = await apiOpenDirectChat(userId); router.push(`/chat/${room.id}`); } catch (e) { toast(e instanceof Error ? e.message : "无法发起私聊"); } finally { setLoading(false); } }; return ( ); }