Communitygithub.com

YepAPI/skills

支持线程评论、@提及、表情反应、审核队列、乐观 UI 和游标分页。

skills 是什么?

该技能提供了一套完整的评论和讨论功能实现,适用于需要用户交互内容的应用场景。它涵盖了从数据模型设计到前端交互的方方面面,包括基于 `parent_id` 的线程化评论系统、通过 React Query 实现的乐观 UI 更新、`@username` 解析与用户通知、独立的反应表及唯一约束、包含发布/标记/删除状态的审核流程、软删除策略、基于游标的分页以及编辑历史记录。技能文档提供了清晰的规则说明、TypeScript 数据模型示例、核心查询和交互代码片段(如线程化查询和乐观添加评论的 mutation),并明确指出了需要避免的常见陷阱(如无限嵌套深度、全量加载、仅客户端解析提及等)。它适用于任何需要构建复杂评论组件或讨论区的 AI 代理或开发者,支持在类似 Cursor 或 Codex 等编码环境中直接参考实现。

兼容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/comments-discussions

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

评论与讨论

规则

  • 线程评论:comments 表中的 parent_id 外键——顶级评论为 null,回复引用其父评论
  • 乐观 UI:将评论立即添加到界面,用服务器响应确认,出错时回滚
  • @提及:解析评论正文中的 @username——在输入 @ 时触发用户查找下拉列表,通知被提及的用户
  • 表情反应:独立的 reactions 表(commentId, userId, emoji)——对 (commentId, userId, emoji) 组合有唯一约束
  • 审核:status 字段(published, flagged, removed)——对标记内容有审核队列,通过敏感词列表自动标记
  • 软删除:设置 deletedAt 时间戳——对有回复的评论显示“已删除”占位符,完全隐藏没有回复的被删除评论
  • 游标分页:cursor(commentId)+ limit——按 createdAt 排序,滚动时加载更早的评论
  • 编辑历史:将编辑记录存储在单独的表或 JSON 数组中——显示“已编辑”指示器和最后编辑时间戳

模式

// 评论数据模型
// comments: id, postId, authorId, parentId(可空), body, status, deletedAt, createdAt, updatedAt
// reactions: id, commentId, userId, emoji, createdAt(唯一:[commentId, userId, emoji])
// mentions: id, commentId, mentionedUserId, createdAt

// 线程查询——获取顶级评论 + 嵌套回复
const comments = await db.query.comments.findMany({
  where: and(eq(comments.postId, postId), isNull(comments.parentId)),
  with: {
    author: { columns: { id: true, name: true, avatar: true } },
    replies: {
      with: { author: { columns: { id: true, name: true, avatar: true } } },
      orderBy: [asc(comments.createdAt)],
    },
    reactions: true,
  },
  orderBy: [desc(comments.createdAt)],
  limit: 20,
});

// 乐观评论添加(React Query)
const addComment = useMutation({
  mutationFn: (body: string) => api.post(`/posts/${postId}/comments`, { body }),
  onMutate: async (body) => {
    await queryClient.cancelQueries({ queryKey: ["comments", postId] });
    const previous = queryClient.getQueryData(["comments", postId]);
    queryClient.setQueryData(["comments", postId], (old: Comment[]) => [
      { id: `temp-${Date.now()}`, body, author: currentUser, createdAt: new Date() },
      ...old,
    ]);
    return { previous };
  },
  onError: (_err, _body, context) => {
    queryClient.setQueryData(["comments", postId], context?.previous);
  },
  onSettled: () => queryClient.invalidateQueries({ queryKey: ["comments", postId] }),
});

避免

  • 无限嵌套深度——限制在 2-3 层,更深的回复则扁平化处理
  • 一次加载所有评论——使用游标分页,尤其是在活跃的讨论中
  • 仅客户端解析提及——应在服务端验证和提取提及以发送通知
  • 硬删除有回复的评论——这会导致线程孤立;应使用软删除并显示占位符
  • 没有唯一约束的反应——允许同一用户重复反应

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Tenant isolation (row-level vs schema), subdomain routing, per-tenant config, and data partitioning.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

相关技能