import React, { useRef, useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { PencilSquareIcon, EyeIcon, PencilIcon, } from '@heroicons/react/24/outline'; import MarkdownRenderer from '../../Shared/MarkdownRenderer'; interface TaskContentCardProps { content: string; onUpdate: (newContent: string) => Promise; } const TaskContentCard: React.FC = ({ content, onUpdate, }) => { const { t } = useTranslation(); const [isEditing, setIsEditing] = useState(false); const [editedContent, setEditedContent] = useState(content); const [contentTab, setContentTab] = useState<'edit' | 'preview'>('edit'); const contentTextareaRef = useRef(null); useEffect(() => { setEditedContent(content); }, [content]); useEffect(() => { if (isEditing && contentTextareaRef.current) { contentTextareaRef.current.focus(); } }, [isEditing]); const handleStartEdit = () => { setIsEditing(true); }; const handleSave = async () => { if (editedContent !== content) { await onUpdate(editedContent); } setIsEditing(false); }; const handleCancel = () => { setEditedContent(content); setIsEditing(false); }; const handleKeyDown = (e: React.KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { handleSave(); } else if (e.key === 'Escape') { handleCancel(); } }; return (
{isEditing ? (
{/* Floating toggle buttons */}
{contentTab === 'edit' ? (