Pages corrections journal

This commit is contained in:
alma 2026-01-16 13:30:37 +01:00
parent 926d78a379
commit becae5e646
3 changed files with 28 additions and 9 deletions

View File

@ -571,9 +571,11 @@ export default function CarnetPage() {
} }
// Refresh the list of notes (skip cache to get fresh data) // Refresh the list of notes (skip cache to get fresh data)
// Note: onRefresh from Editor will also call fetchNotes, but with skipCache=false // Only refresh if not Health folder to avoid constant flickering during form updates
// So we call it with skipCache=true here to ensure fresh data // Health folder updates are handled by the form itself and don't need immediate list refresh
fetchNotes(true); if (selectedFolder !== 'Health') {
fetchNotes(true);
}
} else { } else {
const errorData = await response.json().catch(() => ({})); const errorData = await response.json().catch(() => ({}));
const errorMessage = errorData.message || errorData.error || 'Failed to save note'; const errorMessage = errorData.message || errorData.error || 'Failed to save note';

View File

@ -142,6 +142,19 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
return; 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); setIsSaving(true);
setError(null); setError(null);
try { try {

View File

@ -66,13 +66,17 @@ export const HealthForm: React.FC<HealthFormProps> = ({ content, onContentChange
}, [data.date, date]); }, [data.date, date]);
// Update parent content whenever data changes (with a small delay to avoid too many updates) // 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(() => { useEffect(() => {
const timer = setTimeout(() => { const jsonContent = JSON.stringify(data, null, 2);
const jsonContent = JSON.stringify(data, null, 2); // Only update if content is different from current content
onContentChange(jsonContent); if (jsonContent !== content) {
}, 100); const timer = setTimeout(() => {
return () => clearTimeout(timer); onContentChange(jsonContent);
}, [data, onContentChange]); }, 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) => { const updateField = (field: keyof HealthData, value: any) => {
setData(prev => ({ ...prev, [field]: value })); setData(prev => ({ ...prev, [field]: value }));