@@ -11,7 +11,7 @@ import {
1111 AlertDialogTrigger ,
1212} from "@/lib/components/ui/alert-dialog" ;
1313import { Button } from "@/lib/components/ui/button" ;
14- import { Textarea } from "@/lib/components/ui/textarea" ;
14+ import { EditableTextArea } from "@/lib/components/ui/textarea" ;
1515import { SimpleTooltip } from "@/lib/components/ui/tooltip" ;
1616import { useToast } from "@/lib/components/ui/use-toast" ;
1717import {
@@ -22,13 +22,7 @@ import {
2222 reportCommentAction ,
2323} from "./actions" ;
2424import { ChatBubbleIcon , TrashIcon } from "@radix-ui/react-icons" ;
25- import {
26- useActionState ,
27- useRef ,
28- useState ,
29- useId ,
30- startTransition ,
31- } from "react" ;
25+ import { useRef , useState , useId , startTransition , useTransition } from "react" ;
3226import {
3327 VoteButton ,
3428 VoteButtonState ,
@@ -44,6 +38,7 @@ import { DeleteButton } from "@/app/(app)/_components/delete-button";
4438import { cva , VariantProps } from "class-variance-authority" ;
4539import { cn } from "@/lib/utils" ;
4640import { ShareDropdownButton } from "@/app/(app)/_components/share-button" ;
41+ import { LexicalEditor } from "lexical" ;
4742
4843const commentVariants = cva ( undefined , {
4944 variants : {
@@ -226,7 +221,6 @@ export function NewComment({
226221 postRkey,
227222 postAuthorDid,
228223 extraButton,
229- textAreaRef,
230224 onActionDone,
231225} : {
232226 parentRkey ?: string ;
@@ -237,23 +231,28 @@ export function NewComment({
237231 extraButton ?: React . ReactNode ;
238232 textAreaRef ?: React . RefObject < HTMLTextAreaElement > ;
239233} ) {
234+ const editorRef = useRef < LexicalEditor | null > ( null ) ;
240235 const [ input , setInput ] = useState ( "" ) ;
241- const [ _ , action , isPending ] = useActionState (
242- createCommentAction . bind ( null , { parentRkey, postRkey, postAuthorDid } ) ,
243- undefined ,
244- ) ;
236+ const [ isPending , startTransition ] = useTransition ( ) ;
237+
245238 const id = useId ( ) ;
246239 const textAreaId = `${ id } -comment` ;
247240
248241 return (
249242 < form
250- action = { action }
251243 onSubmit = { ( event ) => {
252244 event . preventDefault ( ) ;
253- startTransition ( ( ) => {
254- action ( new FormData ( event . currentTarget ) ) ;
245+ startTransition ( async ( ) => {
246+ const state = editorRef . current ?. getEditorState ( ) . toJSON ( ) ;
247+ if ( ! state ) throw new Error ( "Empty comment" ) ;
248+ console . log ( state ) ;
249+ await createCommentAction ( {
250+ parentRkey,
251+ postRkey,
252+ postAuthorDid,
253+ content : state ,
254+ } ) ;
255255 onActionDone ?.( ) ;
256- setInput ( "" ) ;
257256 } ) ;
258257 } }
259258 aria-busy = { isPending }
@@ -271,7 +270,7 @@ export function NewComment({
271270 } }
272271 className = "space-y-2"
273272 >
274- < Textarea
273+ < EditableTextArea
275274 value = { input }
276275 onChange = { ( event ) => {
277276 setInput ( event . target . value ) ;
@@ -280,10 +279,10 @@ export function NewComment({
280279 // eslint-disable-next-line jsx-a11y/no-autofocus
281280 autoFocus = { autoFocus }
282281 name = "comment"
283- ref = { textAreaRef }
282+ ref = { editorRef }
284283 placeholder = "Write a comment..."
285284 disabled = { isPending }
286- className = "resize-y flex-1"
285+ className = "resize-y flex-1 overflow-auto grow "
287286 />
288287 < div className = "w-full flex justify-between" >
289288 < InputLengthIndicator
0 commit comments