Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ComposerPendingReviewComments.tsx

60 lines2.0 KB

1import { MessageCircle, X } from "lucide-react";
2​
3import {
4 COMPOSER_INLINE_CHIP_CLASS_NAME,
5 COMPOSER_INLINE_CHIP_DISMISS_BUTTON_CLASS_NAME,
6 COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
7 COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME,
8} from "../composerInlineChip";
9import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
10import type { ReviewCommentContext } from "~/reviewCommentContext";
11import { cn } from "~/lib/utils";
12​
13interface ComposerPendingReviewCommentsProps {
14 comments: ReadonlyArray<ReviewCommentContext>;
15 onRemove: (commentId: string) => void;
16 className?: string;
18​
19export function ComposerPendingReviewComments({
20 comments,
21 onRemove,
22 className,
23}: ComposerPendingReviewCommentsProps) {
24 if (comments.length === 0) return null;
25​
26 return (
27 <div className={cn("flex flex-wrap gap-1.5", className)}>
28 {comments.map((comment) => {
29 const label = `${comment.filePath} ${comment.rangeLabel}`;
30 const chip = (
31 <span key={comment.id} className={cn(COMPOSER_INLINE_CHIP_CLASS_NAME, "pr-1")}>
32 <MessageCircle className={cn(COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, "size-3.5")} />
33 <span className={COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME}>{label}</span>
34 <button
35 type="button"
36 aria-label={`Remove comment on ${label}`}
37 className={COMPOSER_INLINE_CHIP_DISMISS_BUTTON_CLASS_NAME}
38 onClick={(event) => {
39 event.preventDefault();
40 event.stopPropagation();
41 onRemove(comment.id);
42 }}
43 >
44 <X className="size-3" aria-hidden />
45 </button>
46 </span>
47 );
48 if (comment.text.length === 0) return chip;
49 return (
50 <Tooltip key={comment.id}>
51 <TooltipTrigger render={chip} />
52 <TooltipPopup side="top" className="max-w-96 whitespace-pre-wrap leading-tight">
53 {comment.text}
54 </TooltipPopup>
55 </Tooltip>
56 );
57 })}
58 </div>
59 );