diff --git a/app/carnet/page.tsx b/app/carnet/page.tsx index 3c67fe93..ca8b7ec4 100644 --- a/app/carnet/page.tsx +++ b/app/carnet/page.tsx @@ -140,8 +140,11 @@ export default function CarnetPage() { const handleNoteSave = async (note: Note) => { try { - const response = await fetch('/api/nextcloud/files', { - method: note.id ? 'PUT' : 'POST', + const endpoint = note.id ? '/api/nextcloud/files' : '/api/nextcloud/files'; + const method = note.id ? 'PUT' : 'POST'; + + const response = await fetch(endpoint, { + method, headers: { 'Content-Type': 'application/json', }, @@ -158,13 +161,16 @@ export default function CarnetPage() { } const savedNote = await response.json(); - setSelectedNote(savedNote); + setSelectedNote({ + ...savedNote, + content: note.content + }); // Refresh the notes list const notesResponse = await fetch(`/api/nextcloud/files?folder=${selectedFolder}`); if (notesResponse.ok) { - const notes = await notesResponse.json(); - setNotes(notes); + const updatedNotes = await notesResponse.json(); + setNotes(updatedNotes); } } catch (error) { console.error('Error saving note:', error); @@ -254,6 +260,13 @@ export default function CarnetPage() { note={selectedNote} onSave={handleNoteSave} currentFolder={selectedFolder} + onRefresh={() => { + // Refresh the notes list + fetch(`/api/nextcloud/files?folder=${selectedFolder}`) + .then(response => response.json()) + .then(updatedNotes => setNotes(updatedNotes)) + .catch(error => console.error('Error refreshing notes:', error)); + }} /> diff --git a/components/carnet/editor.tsx b/components/carnet/editor.tsx index 8f10c578..78ce098e 100644 --- a/components/carnet/editor.tsx +++ b/components/carnet/editor.tsx @@ -17,9 +17,10 @@ interface EditorProps { note?: Note | null; onSave?: (note: Note) => void; currentFolder?: string; + onRefresh?: () => void; } -export const Editor: React.FC = ({ note, onSave, currentFolder = 'Notes' }) => { +export const Editor: React.FC = ({ note, onSave, currentFolder = 'Notes', onRefresh }) => { const [title, setTitle] = useState(note?.title || ''); const [content, setContent] = useState(note?.content || ''); const [isSaving, setIsSaving] = useState(false); @@ -95,6 +96,7 @@ export const Editor: React.FC = ({ note, onSave, currentFolder = 'N ...savedNote, content }); + onRefresh?.(); } catch (error) { console.error('Error saving note:', error); // TODO: Show error message to user