Pages corrections pages missions
This commit is contained in:
parent
50a7b0c696
commit
441d0f31a4
@ -220,61 +220,25 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
|
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
setError(null);
|
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 {
|
try {
|
||||||
// Construct the full note ID if it doesn't exist yet
|
// Construct a Note object with current state
|
||||||
const noteId = note?.id || `user-${session.user.id}/${currentFolder.toLowerCase()}/${title}${title.endsWith('.md') ? '' : '.md'}`;
|
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';
|
console.log('[Editor] Calling onSave with note (delegating to handleSaveNote):', noteToSave);
|
||||||
const method = note?.id ? 'PUT' : 'POST';
|
// Pass the note to onSave callback, which will call handleSaveNote in page.tsx
|
||||||
|
// handleSaveNote will handle the actual API call with proper duplicate detection
|
||||||
console.log('Saving note:', {
|
onSave?.(noteToSave);
|
||||||
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
|
|
||||||
});
|
|
||||||
// Note: onRefresh is called, but handleSaveNote already calls fetchNotes
|
// Note: onRefresh is called, but handleSaveNote already calls fetchNotes
|
||||||
// So we don't need to call onRefresh here to avoid double fetch
|
// So we don't need to call onRefresh here to avoid double fetch
|
||||||
// onRefresh?.();
|
// onRefresh?.();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user