Communitygithub.com

YepAPI/skills

스레드형 댓글, @멘션, 반응, 중재 대기열, 낙관적 UI 및 커서 페이지네이션을 구현합니다.

skills란 무엇인가요?

이 에이전트 스킬은 댓글 및 토론 시스템을 구축하기 위한 완전한 프론트엔드 및 백엔드 패턴을 제공합니다. 주요 기능으로는 parent_id 기반 스레드형 댓글, @멘션을 통한 사용자 알림, 리액션(이모지) 추가, 게시/차단/삭제 상태를 관리하는 중재 대기열 등이 포함됩니다. 또한, 낙관적 UI를 통해 댓글을 즉시 화면에 표시하고 서버 응답을 확인하며 오류 시 롤백함으로써 사용자 경험을 향상시킵니다. 대량의 댓글을 처리할 때는 cursor 기반 페이지네이션을 사용하여 스크롤에 따라 오래된 댓글을 점진적으로 로드하며, 댓글 삭제 시 소프트 딜리트 방식을 채택하여 대화 맥락을 보존합니다. 이 스킬은 주로 React Query와 같은 클라이언트 라이브러리 및 관계형 데이터베이스(예: Drizzle ORM)와 함께 사용되며, 모든 구현 예제가 TypeScript로 제공됩니다.

지원 대상~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/comments-discussions

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

댓글 및 토론

규칙

  • 스레드형 댓글: 댓글 테이블의 parent_id 외래 키 사용 — null이면 최상위 댓글, 부모를 참조하면 답글
  • 낙관적 UI: 댓글을 즉시 UI에 추가하고, 서버 응답으로 확인하며, 오류 시 롤백
  • @멘션: 댓글 본문에서 @username을 파싱 — @ 키 입력 시 사용자 조회 드롭다운 트리거, 멘션된 사용자에게 알림
  • 반응: 별도 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.

관련 스킬