Skip to content

Commit c70772d

Browse files
committed
move reviewer name into comment popup, style inline author as pill
- Name input is now inside the CommentPopup (not a browser prompt) - Persists in localStorage, pre-fills on subsequent comments - Inline author shown as a colored pill badge distinct from comment text - Remove getReviewerName prompt() function Made-with: Cursor
1 parent 2402549 commit c70772d

2 files changed

Lines changed: 57 additions & 26 deletions

File tree

ui/src/App.tsx

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ function CommentPopup({
2828
onCancel,
2929
}: {
3030
position: { top: number; left: number };
31-
onSave: (text: string) => void;
31+
onSave: (text: string, author: string) => void;
3232
onCancel: () => void;
3333
}) {
3434
const [text, setText] = useState("");
35+
const [name, setName] = useState(
36+
() => localStorage.getItem("cpr-reviewer") ?? "",
37+
);
3538
const textareaRef = useRef<HTMLTextAreaElement>(null);
3639
const popupRef = useRef<HTMLDivElement>(null);
3740

@@ -48,6 +51,13 @@ function CommentPopup({
4851
}
4952
}, [position]);
5053

54+
function submit() {
55+
if (!text.trim()) return;
56+
const author = name.trim();
57+
if (author) localStorage.setItem("cpr-reviewer", author);
58+
onSave(text.trim(), author);
59+
}
60+
5161
return (
5262
<>
5363
<div className="comment-backdrop" onClick={onCancel} />
@@ -56,16 +66,23 @@ function CommentPopup({
5666
className="comment-popup"
5767
style={{ top: position.top, left: position.left }}
5868
>
69+
<input
70+
className="comment-popup-name"
71+
placeholder="Your name (optional)"
72+
value={name}
73+
onChange={(e) => setName(e.target.value)}
74+
onKeyDown={(e) => {
75+
if (e.key === "Escape") onCancel();
76+
}}
77+
/>
5978
<textarea
6079
ref={textareaRef}
6180
className="comment-popup-textarea"
6281
placeholder="Leave a comment..."
6382
value={text}
6483
onChange={(e) => setText(e.target.value)}
6584
onKeyDown={(e) => {
66-
if (e.key === "Enter" && (e.metaKey || e.ctrlKey) && text.trim()) {
67-
onSave(text.trim());
68-
}
85+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) submit();
6986
if (e.key === "Escape") onCancel();
7087
}}
7188
rows={2}
@@ -75,7 +92,7 @@ function CommentPopup({
7592
<button
7693
className="comment-popup-submit"
7794
disabled={!text.trim()}
78-
onClick={() => text.trim() && onSave(text.trim())}
95+
onClick={submit}
7996
>
8097
Comment
8198
</button>
@@ -241,12 +258,13 @@ function PlanViewer({
241258
}, [highlightedText]);
242259

243260
const handleCommentSave = useCallback(
244-
(text: string) => {
261+
(text: string, author: string) => {
245262
if (!commentTarget) return;
246263
onAnnotationCreate({
247264
type: "COMMENT",
248265
originalText: commentTarget.text.slice(0, 120),
249266
text,
267+
...(author ? { author } : {}),
250268
});
251269
setCommentTarget(null);
252270
},
@@ -742,27 +760,11 @@ export default function App() {
742760
});
743761
}
744762

745-
function getReviewerName(): string {
746-
let name = localStorage.getItem("cpr-reviewer") ?? "";
747-
if (!name) {
748-
const input = prompt("Your name (shown on review notes):");
749-
name = input?.trim() ?? "";
750-
if (name) localStorage.setItem("cpr-reviewer", name);
751-
}
752-
return name;
753-
}
754-
755763
const addAnnotation = useCallback(
756764
(ann: Omit<Annotation, "id" | "createdAt">) => {
757-
const author = getReviewerName();
758765
setAnnotations((prev) => [
759766
...prev,
760-
{
761-
...ann,
762-
id: crypto.randomUUID(),
763-
createdAt: Date.now(),
764-
...(author ? { author } : {}),
765-
},
767+
{ ...ann, id: crypto.randomUUID(), createdAt: Date.now() },
766768
]);
767769
},
768770
[],
@@ -775,7 +777,13 @@ export default function App() {
775777
const addGlobalComment = useCallback(() => {
776778
const text = prompt("Add a global note for the team:");
777779
if (text?.trim()) {
778-
addAnnotation({ type: "GLOBAL_COMMENT", originalText: "", text });
780+
const author = localStorage.getItem("cpr-reviewer") ?? "";
781+
addAnnotation({
782+
type: "GLOBAL_COMMENT",
783+
originalText: "",
784+
text,
785+
...(author ? { author } : {}),
786+
});
779787
}
780788
}, [addAnnotation]);
781789

ui/src/app.css

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,15 @@ mark.ann-insert {
448448
}
449449

450450
.ann-author {
451+
display: inline-block;
451452
font-weight: 600;
452-
color: var(--text);
453-
font-size: 12px;
453+
color: var(--blue);
454+
font-size: 11px;
455+
background: color-mix(in srgb, var(--blue) 12%, transparent);
456+
padding: 1px 6px;
457+
border-radius: 3px;
458+
margin-right: 4px;
459+
vertical-align: baseline;
454460
}
455461

456462
mark.sidebar-highlight {
@@ -489,6 +495,23 @@ mark.sidebar-highlight {
489495
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
490496
}
491497

498+
.comment-popup-name {
499+
width: 100%;
500+
background: var(--surface2);
501+
border: none;
502+
border-bottom: 1px solid var(--border);
503+
color: var(--text);
504+
padding: 8px 12px;
505+
font-size: 13px;
506+
font-family: inherit;
507+
outline: none;
508+
}
509+
510+
.comment-popup-name::placeholder {
511+
color: var(--text-muted);
512+
font-style: italic;
513+
}
514+
492515
.comment-popup-textarea {
493516
width: 100%;
494517
min-height: 56px;

0 commit comments

Comments
 (0)