feat: 就地通过评审,并为已过审用户提供默认可关的免审发布
帖/评管理入口可直接通过;站点默认信任已有 published 内容的用户后续直发。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,9 +3,17 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { Trash2, MessagesSquare, ChevronRight, ChevronDown } from "lucide-react";
|
||||
import { Trash2, MessagesSquare, ChevronRight, ChevronDown, BadgeCheck } from "lucide-react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import { apiCreateComment, apiDeleteComment, apiAcceptBounty, apiAcceptQuestion, type CommentNode, type User } from "@/lib/api";
|
||||
import {
|
||||
apiCreateComment,
|
||||
apiDeleteComment,
|
||||
apiAcceptBounty,
|
||||
apiAcceptQuestion,
|
||||
apiAdminApproveComment,
|
||||
type CommentNode,
|
||||
type User,
|
||||
} from "@/lib/api";
|
||||
import { canModerateBoard } from "@/lib/roles";
|
||||
import { toast } from "@/lib/toast";
|
||||
import Avatar from "./Avatar";
|
||||
@@ -59,6 +67,7 @@ export default function CommentSection({
|
||||
const [deletingId, setDeletingId] = useState<number | null>(null);
|
||||
const [confirmingId, setConfirmingId] = useState<number | null>(null);
|
||||
const [acceptingId, setAcceptingId] = useState<number | null>(null);
|
||||
const [approvingId, setApprovingId] = useState<number | null>(null);
|
||||
// 折叠状态:哪些楼层展开了子回复(默认全部折叠,SSR 初始为收起)
|
||||
const [expandedFloors, setExpandedFloors] = useState<Set<number>>(new Set());
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
@@ -163,11 +172,27 @@ export default function CommentSection({
|
||||
}
|
||||
};
|
||||
|
||||
const handleApprove = async (commentId: number) => {
|
||||
setApprovingId(commentId);
|
||||
try {
|
||||
await apiAdminApproveComment(commentId);
|
||||
toast("已通过评审", "ok");
|
||||
router.refresh();
|
||||
} catch (e) {
|
||||
toast(e instanceof Error ? e.message : "通过评审失败");
|
||||
} finally {
|
||||
setApprovingId(null);
|
||||
}
|
||||
};
|
||||
|
||||
// 引用功能已移除:与"回复"功能重叠,且会割裂讨论上下文(抖音风格无此功能)
|
||||
|
||||
const canDelete = (comment: CommentNode) =>
|
||||
!!user && (user.id === comment.user.id || canModerateBoard(user, boardId));
|
||||
|
||||
const canApprove = (comment: CommentNode) =>
|
||||
!!user && comment.status === "pending" && canModerateBoard(user, boardId);
|
||||
|
||||
const canAccept = (comment: CommentNode) =>
|
||||
!!acceptMode &&
|
||||
!!user &&
|
||||
@@ -302,6 +327,18 @@ export default function CommentSection({
|
||||
{acceptingId === c.id ? "采纳中…" : acceptMode === "question" ? "采纳答案" : "采纳"}
|
||||
</button>
|
||||
)}
|
||||
{canApprove(c) && (
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id}
|
||||
onClick={() => void handleApprove(c.id)}
|
||||
data-tip="通过评审,公开此评论"
|
||||
>
|
||||
<BadgeCheck size={13} />
|
||||
{approvingId === c.id ? "通过中…" : "通过评审"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{canDelete(c) && (
|
||||
<button
|
||||
@@ -394,6 +431,18 @@ export default function CommentSection({
|
||||
{acceptingId === c.id ? "采纳中…" : acceptMode === "question" ? "采纳答案" : "采纳"}
|
||||
</button>
|
||||
)}
|
||||
{canApprove(c) && (
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id}
|
||||
onClick={() => void handleApprove(c.id)}
|
||||
data-tip="通过评审,公开此评论"
|
||||
>
|
||||
<BadgeCheck size={13} />
|
||||
{approvingId === c.id ? "通过中…" : "通过评审"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{canDelete(c) && (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user