diff --git a/src/components/SkillCommentsPanel.tsx b/src/components/SkillCommentsPanel.tsx new file mode 100644 index 0000000..3dbc7e1 --- /dev/null +++ b/src/components/SkillCommentsPanel.tsx @@ -0,0 +1,77 @@ +import { useMutation, useQuery } from 'convex/react' +import { useState } from 'react' +import { api } from '../../convex/_generated/api' +import type { Doc, Id } from '../../convex/_generated/dataModel' + +type SkillCommentsPanelProps = { + skillId: Id<'skills'> + isAuthenticated: boolean + me: Doc<'users'> | null +} + +export function SkillCommentsPanel({ skillId, isAuthenticated, me }: SkillCommentsPanelProps) { + const addComment = useMutation(api.comments.add) + const removeComment = useMutation(api.comments.remove) + const [comment, setComment] = useState('') + const comments = useQuery(api.comments.listBySkill, { skillId, limit: 50 }) as + | Array<{ comment: Doc<'comments'>; user: Doc<'users'> | null }> + | undefined + + return ( +
+

+ Comments +

+ {isAuthenticated ? ( +
{ + event.preventDefault() + if (!comment.trim()) return + void addComment({ skillId, body: comment.trim() }).then(() => setComment('')) + }} + className="comment-form" + > +