mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-20 13:48:20 +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 editorRef = useRef<HTMLDivElement>(null);
|
||||||
const [selectedFormat, setSelectedFormat] = useState<string[]>([]);
|
const [selectedFormat, setSelectedFormat] = useState<string[]>([]);
|
||||||
|
|
||||||
|
// Set initial content only once on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (editorRef.current && editorRef.current.innerHTML !== content) {
|
if (editorRef.current) {
|
||||||
editorRef.current.innerHTML = content;
|
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) => {
|
const execCommand = (command: string, value?: string) => {
|
||||||
document.execCommand(command, false, value);
|
document.execCommand(command, false, value);
|
||||||
|
|||||||
+6
-3
@@ -217,9 +217,9 @@ const Index = () => {
|
|||||||
const handleContentChange = useCallback((content: string) => {
|
const handleContentChange = useCallback((content: string) => {
|
||||||
if (!openNote) return;
|
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 };
|
const updatedNote = { ...openNote, content };
|
||||||
setOpenNote(updatedNote);
|
|
||||||
|
|
||||||
// Debounce the API call
|
// Debounce the API call
|
||||||
if (saveTimerRef.current) {
|
if (saveTimerRef.current) {
|
||||||
@@ -229,11 +229,13 @@ const Index = () => {
|
|||||||
saveTimerRef.current = setTimeout(async () => {
|
saveTimerRef.current = setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
await NotesService.updateNote(updatedNote);
|
await NotesService.updateNote(updatedNote);
|
||||||
|
// Update notes list silently after save
|
||||||
|
setNotes(prev => prev.map(note => note.id === updatedNote.id ? updatedNote : note));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showError("Erreur lors de la sauvegarde automatique");
|
showError("Erreur lors de la sauvegarde automatique");
|
||||||
}
|
}
|
||||||
}, 1000); // Save after 1 second of inactivity
|
}, 1000); // Save after 1 second of inactivity
|
||||||
}, [openNote]);
|
}, [openNote, setNotes]);
|
||||||
|
|
||||||
// Clean up timer on unmount
|
// Clean up timer on unmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -625,6 +627,7 @@ const Index = () => {
|
|||||||
|
|
||||||
<TabsContent value="content" className="mt-4">
|
<TabsContent value="content" className="mt-4">
|
||||||
<RichTextEditor
|
<RichTextEditor
|
||||||
|
key={openNote.id}
|
||||||
content={openNote.content || ""}
|
content={openNote.content || ""}
|
||||||
onChange={handleContentChange}
|
onChange={handleContentChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user