mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-11 17:29:37 +02:00
Fix CRITIQUE: Écriture fluide dans les notes réparée
This commit is contained in:
2 files changed
+10
-5
No files matched your search
@@ -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
@@ -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}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user