From becae5e6462c72c95fe6741236f10006444af5a9 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 13:30:37 +0100 Subject: [PATCH] Pages corrections journal --- app/pages/page.tsx | 8 +++++--- components/carnet/editor.tsx | 13 +++++++++++++ components/carnet/health-form.tsx | 16 ++++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/pages/page.tsx b/app/pages/page.tsx index 1060406..f44b62c 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -571,9 +571,11 @@ export default function CarnetPage() { } // Refresh the list of notes (skip cache to get fresh data) - // Note: onRefresh from Editor will also call fetchNotes, but with skipCache=false - // So we call it with skipCache=true here to ensure fresh data - fetchNotes(true); + // Only refresh if not Health folder to avoid constant flickering during form updates + // Health folder updates are handled by the form itself and don't need immediate list refresh + if (selectedFolder !== 'Health') { + fetchNotes(true); + } } else { const errorData = await response.json().catch(() => ({})); const errorMessage = errorData.message || errorData.error || 'Failed to save note'; diff --git a/components/carnet/editor.tsx b/components/carnet/editor.tsx index 75007fd..157c31f 100644 --- a/components/carnet/editor.tsx +++ b/components/carnet/editor.tsx @@ -142,6 +142,19 @@ export const Editor: React.FC = ({ note, onSave, currentFolder = 'N return; } + // For Health folder, don't save if content is just empty JSON + if (currentFolder === 'Health') { + try { + const parsed = JSON.parse(content); + const isEmpty = Object.keys(parsed).length === 0 || (Object.keys(parsed).length === 1 && parsed.date); + if (isEmpty) { + return; // Don't save empty health forms + } + } catch { + // If not valid JSON, continue with save + } + } + setIsSaving(true); setError(null); try { diff --git a/components/carnet/health-form.tsx b/components/carnet/health-form.tsx index 25539ba..7454ba6 100644 --- a/components/carnet/health-form.tsx +++ b/components/carnet/health-form.tsx @@ -66,13 +66,17 @@ export const HealthForm: React.FC = ({ content, onContentChange }, [data.date, date]); // Update parent content whenever data changes (with a small delay to avoid too many updates) + // Only update if content actually changed to prevent infinite loops useEffect(() => { - const timer = setTimeout(() => { - const jsonContent = JSON.stringify(data, null, 2); - onContentChange(jsonContent); - }, 100); - return () => clearTimeout(timer); - }, [data, onContentChange]); + const jsonContent = JSON.stringify(data, null, 2); + // Only update if content is different from current content + if (jsonContent !== content) { + const timer = setTimeout(() => { + onContentChange(jsonContent); + }, 500); // Increased delay to reduce updates + return () => clearTimeout(timer); + } + }, [data]); // Removed onContentChange and content from dependencies to prevent loops const updateField = (field: keyof HealthData, value: any) => { setData(prev => ({ ...prev, [field]: value }));