diff --git a/frontend/src/Components/ApplicationCommentForm/ApplicationCommentForm.tsx b/frontend/src/Components/ApplicationCommentForm/ApplicationCommentForm.tsx new file mode 100644 index 000000000..cfe63b4ae --- /dev/null +++ b/frontend/src/Components/ApplicationCommentForm/ApplicationCommentForm.tsx @@ -0,0 +1,42 @@ +import type React from 'react'; +import { useEffect, useRef, useState } from 'react'; +import { Textarea } from '~/Components'; + +type CommentFormProps = { + commentText?: string; + handlePost: () => void; +}; + +export function ApplicationCommentForm({ commentText, handlePost }: CommentFormProps) { + const [comment, setComment] = useState(commentText || ''); + const textareaRef = useRef(null); + const prevCommentRef = useRef(comment); + + // Update state if initialData changes + useEffect(() => { + setComment(commentText || ''); + }, [commentText]); + + // Handle blur event + const handleBlur = (event: React.FocusEvent) => { + // TODO: implement actuall comment logic + const newValue = event.target.value; + + // Only update if the value has changed + if (newValue !== prevCommentRef.current) { + // Update the ref to the current value + prevCommentRef.current = newValue; + + // Update state + setComment(newValue); + + handlePost(); + } + }; + + return ( +
+