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)
|
// 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
|
||||||
|
if (selectedFolder !== 'Health') {
|
||||||
fetchNotes(true);
|
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';
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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
|
||||||
|
if (jsonContent !== content) {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
onContentChange(jsonContent);
|
onContentChange(jsonContent);
|
||||||
}, 100);
|
}, 500); // Increased delay to reduce updates
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [data, onContentChange]);
|
}
|
||||||
|
}, [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 }));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user