@@ -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
0 commit comments