Pages corrections pages health
This commit is contained in:
parent
441d0f31a4
commit
850cae5aa0
@ -180,23 +180,30 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
// Handle content change from HealthForm (direct string update)
|
// Handle content change from HealthForm (direct string update)
|
||||||
const handleHealthContentChange = (newContent: string) => {
|
const handleHealthContentChange = (newContent: string) => {
|
||||||
setContent(newContent);
|
setContent(newContent);
|
||||||
debouncedSave();
|
// For Health folder, pass the newContent directly to debouncedSave to ensure we use the latest content
|
||||||
|
// This is important because setContent is async and content state might not be updated when debouncedSave fires
|
||||||
|
debouncedSave(newContent);
|
||||||
};
|
};
|
||||||
|
|
||||||
const debouncedSave = () => {
|
const debouncedSave = (contentToSave?: string) => {
|
||||||
if (saveTimeout.current) {
|
if (saveTimeout.current) {
|
||||||
clearTimeout(saveTimeout.current);
|
clearTimeout(saveTimeout.current);
|
||||||
}
|
}
|
||||||
saveTimeout.current = setTimeout(() => {
|
saveTimeout.current = setTimeout(() => {
|
||||||
console.log(`[Editor] debouncedSave triggered for folder: ${currentFolder}`);
|
console.log(`[Editor] debouncedSave triggered for folder: ${currentFolder}`);
|
||||||
handleSave();
|
// Use the provided contentToSave if available, otherwise use state content
|
||||||
|
handleSave(contentToSave);
|
||||||
}, 1000); // Save after 1 second of inactivity
|
}, 1000); // Save after 1 second of inactivity
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async (contentToSave?: string) => {
|
||||||
console.log(`[Editor] handleSave called - folder: ${currentFolder}, title: "${title}", content length: ${content?.length || 0}`);
|
// Use the provided contentToSave if available, otherwise use state content
|
||||||
if (!title || !content) {
|
// This ensures we use the latest content from HealthForm even if state hasn't updated yet
|
||||||
console.log(`[Editor] handleSave: Skipping save - title: "${title}", content: "${content}"`);
|
const contentToUse = contentToSave !== undefined ? contentToSave : content;
|
||||||
|
|
||||||
|
console.log(`[Editor] handleSave called - folder: ${currentFolder}, title: "${title}", content length: ${contentToUse?.length || 0}`);
|
||||||
|
if (!title || !contentToUse) {
|
||||||
|
console.log(`[Editor] handleSave: Skipping save - title: "${title}", content: "${contentToUse}"`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!session) {
|
if (!session) {
|
||||||
@ -208,9 +215,10 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
// For Health folder, don't save if content is just empty JSON
|
// For Health folder, don't save if content is just empty JSON
|
||||||
if (currentFolder === 'Health') {
|
if (currentFolder === 'Health') {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(content);
|
const parsed = JSON.parse(contentToUse);
|
||||||
const isEmpty = Object.keys(parsed).length === 0 || (Object.keys(parsed).length === 1 && parsed.date);
|
const isEmpty = Object.keys(parsed).length === 0 || (Object.keys(parsed).length === 1 && parsed.date);
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
|
console.log('[Editor] handleSave: Skipping save for empty Health form');
|
||||||
return; // Don't save empty health forms
|
return; // Don't save empty health forms
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@ -228,14 +236,14 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
const noteToSave: Note = {
|
const noteToSave: Note = {
|
||||||
id: note?.id || '', // Use existing note.id if available, otherwise empty (will be determined in handleSaveNote)
|
id: note?.id || '', // Use existing note.id if available, otherwise empty (will be determined in handleSaveNote)
|
||||||
title: title, // Use the title from local state
|
title: title, // Use the title from local state
|
||||||
content: content, // Use the content from local state
|
content: contentToUse, // Use the provided content or state content
|
||||||
lastModified: note?.lastModified || new Date().toISOString(),
|
lastModified: note?.lastModified || new Date().toISOString(),
|
||||||
type: note?.type || 'file',
|
type: note?.type || 'file',
|
||||||
mime: note?.mime || 'text/markdown',
|
mime: note?.mime || 'text/markdown',
|
||||||
etag: note?.etag || ''
|
etag: note?.etag || ''
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[Editor] Calling onSave with note (delegating to handleSaveNote):', noteToSave);
|
console.log('[Editor] Calling onSave with note (delegating to handleSaveNote):', { ...noteToSave, content: `[${contentToUse.length} chars]` });
|
||||||
// Pass the note to onSave callback, which will call handleSaveNote in page.tsx
|
// Pass the note to onSave callback, which will call handleSaveNote in page.tsx
|
||||||
// handleSaveNote will handle the actual API call with proper duplicate detection
|
// handleSaveNote will handle the actual API call with proper duplicate detection
|
||||||
onSave?.(noteToSave);
|
onSave?.(noteToSave);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user