Communitygithub.com

YepAPI/skills

スレッドコメント、@メンション、リアクション、モデレーションキュー、楽観的UI、カーソルページネーション。

skills とは?

このスキルは、開発者が高機能なコメント・ディスカッションシステムを効率的に実装するための設計パターンと実装ガイドを提供します。スレッド型コメント、@メンション、絵文字リアクション、モデレーション機能、楽観的UI、カーソルページネーション、編集履歴など、モダンなコメントシステムに必要な主要機能を網羅しています。主にWebアプリケーションフレームワークとデータベース(SQL系、Drizzle ORMなど)向けに設計されており、TypeScriptとReact Queryを用いた具体的なコードパターンが含まれています。データモデル定義から楽観的更新の実装、サーバーサイドバリデーション、モデレーションキューまで、実運用を想定した堅牢な設計が特徴です。また、無限のネスト深度や全コメント一括読み込みなど、避けるべきアンチパターンも明確に示しており、開発者が陥りやすい落とし穴を回避できます。

対応~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/comments-discussions

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

コメントとディスカッション

ルール

  • スレッド型コメント: commentsテーブルの外部キー parent_id — トップレベルは null、返信は親を参照
  • 楽観的UI: コメントを即座にUIに追加、サーバー応答で確定、エラー時はロールバック
  • @メンション: コメント本文内の @ユーザー名 を解析 — @ キー入力時にユーザー検索ドロップダウンを表示、メンションされたユーザーに通知
  • リアクション: 独立した reactions テーブル (commentId, userId, emoji) — (commentId, userId, emoji) に一意制約
  • モデレーション: status フィールド (published, flagged, removed) — フラグ付きコンテンツのモデレーションキュー、ワードリストによる自動フラグ
  • ソフトデリート: deletedAt タイムスタンプを設定 — 返信があるコメントは「削除済み」プレースホルダーを表示、孤立した削除コメントは完全非表示
  • カーソルページネーション: cursor (commentId) + limit — createdAt でソート、スクロールで古いコメントを読み込み
  • 編集履歴: 編集内容を別テーブルまたはJSON配列に保存 — 最終編集タイムスタンプと共に「編集済み」インジケーターを表示

パターン

// コメントデータモデル
// comments: id, postId, authorId, parentId (nullable), body, status, deletedAt, createdAt, updatedAt
// reactions: id, commentId, userId, emoji, createdAt (unique: [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.

関連スキル