Pages corrections pages health

This commit is contained in:
alma 2026-01-16 16:56:37 +01:00
parent e5254c8bc8
commit 091b598d1b
2 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -59,6 +59,25 @@ export const HealthForm: React.FC<HealthFormProps> = ({ content, onContentChange
// Use ref to track last sent content to prevent infinite loops
const lastSentContentRef = useRef<string>('');
// 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) {