"use client"; import { useEffect, useState, type KeyboardEvent, type MouseEvent, } from "react"; import { getRepliesForParent } from "../core/comment-threads"; import type { CommentAnnotation } from "../core/types"; import { Button } from "@prototype/components/ui/button"; import { useCommentStore } from "../react/CommentProvider"; import { CommentAuthorAvatar } from "./comment-author-avatar"; import threadStyles from "./comment-thread.module.scss"; import { cn } from "@prototype/lib/utils"; const THREAD_CANCEL_BUTTON_CLASS = "h-7 border-[var(--tool-chrome-border)] bg-transparent px-2.5 text-xs text-[var(--tool-chrome-text-muted)] shadow-none hover:bg-[var(--tool-chrome-gray-highlight)] hover:text-[var(--tool-chrome-text)]"; const THREAD_PRIMARY_BUTTON_CLASS = "h-7 px-2.5 text-xs"; function PencilIcon() { return ( ); } function TrashIcon() { return ( ); } type ThreadReplyRowProps = { reply: CommentAnnotation; canModify: boolean; dark?: boolean; }; function ThreadReplyRow({ reply, canModify, dark = false, }: ThreadReplyRowProps) { const { updateAnnotation, deleteAnnotation } = useCommentStore(); const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(reply.comment); const [actionsVisible, setActionsVisible] = useState(false); useEffect(() => { setDraft(reply.comment); }, [reply.comment]); function handleSave() { const text = draft.trim(); if (!text) return; updateAnnotation(reply.id, text); setEditing(false); } function handleKeyDown(event: KeyboardEvent) { event.stopPropagation(); if (event.key === "Enter" && !event.shiftKey) { event.preventDefault(); handleSave(); } if (event.key === "Escape") { setDraft(reply.comment); setEditing(false); } } return (
setActionsVisible(true)} onMouseLeave={() => setActionsVisible(false)} > {editing ? (