From a1d3abc874834240571bde5ae5c4e80df8213809 Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 21 Apr 2025 18:17:07 +0200 Subject: [PATCH] mail page fix --- components/ComposeEmail.tsx | 47 ++++++++++++++----------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 3df6750f..4dc248a4 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useRef } from 'react'; +import { useRef, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; @@ -51,6 +51,19 @@ export default function ComposeEmail({ }: ComposeEmailProps) { const composeBodyRef = useRef(null); + // Update the contentEditable div when composeBody changes + useEffect(() => { + if (composeBodyRef.current && composeBody) { + composeBodyRef.current.innerHTML = composeBody; + } + }, [composeBody]); + + const handleInput = (e: React.FormEvent) => { + if (composeBodyRef.current) { + setComposeBody(composeBodyRef.current.innerHTML); + } + }; + const handleFileAttachment = async (e: React.ChangeEvent) => { if (!e.target.files) return; @@ -203,35 +216,9 @@ export default function ComposeEmail({
) => { - const content = (e.target as HTMLDivElement).innerHTML; - setComposeBody(content); - }} - onKeyDown={(e: React.KeyboardEvent) => { - if (e.key === 'Enter') { - e.preventDefault(); - document.execCommand('insertLineBreak'); - } - }} - onFocus={() => { - const current = composeBodyRef.current; - if (current && !current.innerHTML) { - current.innerHTML = ''; - } - }} - style={{ - outline: 'none', - cursor: 'text', - whiteSpace: 'pre-wrap', - wordBreak: 'break-word', - minHeight: '200px', - padding: '1rem', - border: '1px solid #e5e7eb', - borderRadius: '0.375rem', - color: '#111827' // text-gray-900 - }} + className="flex-1 p-4 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 prose max-w-none" + onInput={handleInput} + dangerouslySetInnerHTML={{ __html: composeBody }} />