Pages corrections pages missions

This commit is contained in:
alma 2026-01-16 15:53:54 +01:00
parent 50a7b0c696
commit 441d0f31a4

View File

@ -220,61 +220,25 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
setIsSaving(true);
setError(null);
// Instead of saving directly, construct a Note object and pass it to onSave
// This ensures handleSaveNote in page.tsx handles all the logic consistently
try {
// Construct the full note ID if it doesn't exist yet
const noteId = note?.id || `user-${session.user.id}/${currentFolder.toLowerCase()}/${title}${title.endsWith('.md') ? '' : '.md'}`;
// Construct a Note object with current state
const noteToSave: Note = {
id: note?.id || '', // Use existing note.id if available, otherwise empty (will be determined in handleSaveNote)
title: title, // Use the title from local state
content: content, // Use the content from local state
lastModified: note?.lastModified || new Date().toISOString(),
type: note?.type || 'file',
mime: note?.mime || 'text/markdown',
etag: note?.etag || ''
};
const endpoint = '/api/storage/files';
const method = note?.id ? 'PUT' : 'POST';
console.log('Saving note:', {
id: noteId,
title,
folder: currentFolder,
contentLength: content.length
});
const response = await fetch(endpoint, {
method,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: noteId,
title,
content,
folder: currentFolder.toLowerCase()
}),
});
if (response.status === 401) {
console.error('Authentication error, redirecting to login');
router.push('/signin');
return;
}
if (!response.ok) {
const errorData = await response.text();
console.error('Failed to save note:', {
status: response.status,
statusText: response.statusText,
data: errorData
});
setError(`Failed to save note: ${response.statusText}`);
throw new Error(`Failed to save note: ${response.status} ${response.statusText}`);
}
const savedNote = await response.json();
console.log('Note saved successfully:', savedNote);
// Update content cache after successful save
noteContentCache.set(noteId, content);
setError(null);
onSave?.({
...savedNote,
content
});
console.log('[Editor] Calling onSave with note (delegating to handleSaveNote):', noteToSave);
// Pass the note to onSave callback, which will call handleSaveNote in page.tsx
// handleSaveNote will handle the actual API call with proper duplicate detection
onSave?.(noteToSave);
// Note: onRefresh is called, but handleSaveNote already calls fetchNotes
// So we don't need to call onRefresh here to avoid double fetch
// onRefresh?.();