From 091b598d1b0df6c229da8db1371b960a08b14ccc Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 16:56:37 +0100 Subject: [PATCH] Pages corrections pages health --- app/pages/page.tsx | 10 ++++++++++ components/carnet/health-form.tsx | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/pages/page.tsx b/app/pages/page.tsx index 3a93408..6cddb9d 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -753,6 +753,16 @@ export default function CarnetPage() { noteContentCache.set(payload.id, payload.content); } + // For Health folder, update selectedNote with the new content so the form reflects the saved data + if (selectedFolder === 'Health' && selectedNote?.id === fileKey) { + console.log(`[handleSaveNote] Updating selectedNote content for Health form`); + setSelectedNote({ + ...selectedNote, + content: payload.content, + lastModified: new Date().toISOString() + }); + } + // Refresh the list of notes (skip cache to get fresh data) // 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 diff --git a/components/carnet/health-form.tsx b/components/carnet/health-form.tsx index a51de1c..ca88fc2 100644 --- a/components/carnet/health-form.tsx +++ b/components/carnet/health-form.tsx @@ -59,6 +59,25 @@ export const HealthForm: React.FC = ({ content, onContentChange // Use ref to track last sent content to prevent infinite loops const lastSentContentRef = useRef(''); + // Update data when content prop changes (e.g., after save or when note is loaded) + useEffect(() => { + if (content && content !== lastSentContentRef.current) { + try { + const parsed = JSON.parse(content); + // Only update if the parsed content is different from current data + // This prevents overwriting user's current edits + const currentJson = JSON.stringify(data); + const newJson = JSON.stringify(parsed); + if (currentJson !== newJson) { + console.log('[HealthForm] Updating data from content prop'); + setData(parsed); + } + } catch { + // If not valid JSON, ignore + } + } + }, [content]); // Only depend on content, not on data to avoid loops + // Initialize date if not set useEffect(() => { if (!data.date && date) {