Pages corrections journal
This commit is contained in:
parent
926d78a379
commit
becae5e646
@ -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';
|
||||
|
||||
@ -142,6 +142,19 @@ export const Editor: React.FC<EditorProps> = ({ 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 {
|
||||
|
||||
@ -66,13 +66,17 @@ export const HealthForm: React.FC<HealthFormProps> = ({ 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 }));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user