Fix CRITIQUE: Écriture fluide dans les notes réparée

This commit is contained in:
Claude committed 2025-11-12 09:37:00 +00:00
1 parent a36bb04c66
commit ece7232f0d
2 files changed
+10 -5

No files matched your search

+4 -2
View File
@@ -29,11 +29,13 @@ export function RichTextEditor({ content, onChange, placeholder }: RichTextEdito
const editorRef = useRef<HTMLDivElement>(null);
const [selectedFormat, setSelectedFormat] = useState<string[]>([]);
// Set initial content only once on mount
useEffect(() => {
if (editorRef.current && editorRef.current.innerHTML !== content) {
if (editorRef.current) {
editorRef.current.innerHTML = content;
}
}, [content]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Empty deps - only run once on mount
const execCommand = (command: string, value?: string) => {
document.execCommand(command, false, value);
+6 -3
View File
@@ -217,9 +217,9 @@ const Index = () => {
const handleContentChange = useCallback((content: string) => {
if (!openNote) return;
// Update local state immediately for responsiveness
// Don't update local state to avoid re-render during typing
// Just save to API in background
const updatedNote = { ...openNote, content };
setOpenNote(updatedNote);
// Debounce the API call
if (saveTimerRef.current) {
@@ -229,11 +229,13 @@ const Index = () => {
saveTimerRef.current = setTimeout(async () => {
try {
await NotesService.updateNote(updatedNote);
// Update notes list silently after save
setNotes(prev => prev.map(note => note.id === updatedNote.id ? updatedNote : note));
} catch (error) {
showError("Erreur lors de la sauvegarde automatique");
}
}, 1000); // Save after 1 second of inactivity
}, [openNote]);
}, [openNote, setNotes]);
// Clean up timer on unmount
useEffect(() => {
@@ -625,6 +627,7 @@ const Index = () => {
<TabsContent value="content" className="mt-4">
<RichTextEditor
key={openNote.id}
content={openNote.content || ""}
onChange={handleContentChange}
/>