carnet panel

This commit is contained in:
alma 2025-04-20 18:37:17 +02:00
parent 29028325a7
commit 90ead6be7f
2 changed files with 21 additions and 6 deletions

View File

@ -140,8 +140,11 @@ export default function CarnetPage() {
const handleNoteSave = async (note: Note) => { const handleNoteSave = async (note: Note) => {
try { try {
const response = await fetch('/api/nextcloud/files', { const endpoint = note.id ? '/api/nextcloud/files' : '/api/nextcloud/files';
method: note.id ? 'PUT' : 'POST', const method = note.id ? 'PUT' : 'POST';
const response = await fetch(endpoint, {
method,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
@ -158,13 +161,16 @@ export default function CarnetPage() {
} }
const savedNote = await response.json(); const savedNote = await response.json();
setSelectedNote(savedNote); setSelectedNote({
...savedNote,
content: note.content
});
// Refresh the notes list // Refresh the notes list
const notesResponse = await fetch(`/api/nextcloud/files?folder=${selectedFolder}`); const notesResponse = await fetch(`/api/nextcloud/files?folder=${selectedFolder}`);
if (notesResponse.ok) { if (notesResponse.ok) {
const notes = await notesResponse.json(); const updatedNotes = await notesResponse.json();
setNotes(notes); setNotes(updatedNotes);
} }
} catch (error) { } catch (error) {
console.error('Error saving note:', error); console.error('Error saving note:', error);
@ -254,6 +260,13 @@ export default function CarnetPage() {
note={selectedNote} note={selectedNote}
onSave={handleNoteSave} onSave={handleNoteSave}
currentFolder={selectedFolder} 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));
}}
/> />
</div> </div>

View File

@ -17,9 +17,10 @@ interface EditorProps {
note?: Note | null; note?: Note | null;
onSave?: (note: Note) => void; onSave?: (note: Note) => void;
currentFolder?: string; currentFolder?: string;
onRefresh?: () => void;
} }
export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'Notes' }) => { export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'Notes', onRefresh }) => {
const [title, setTitle] = useState(note?.title || ''); const [title, setTitle] = useState(note?.title || '');
const [content, setContent] = useState(note?.content || ''); const [content, setContent] = useState(note?.content || '');
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
@ -95,6 +96,7 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
...savedNote, ...savedNote,
content content
}); });
onRefresh?.();
} catch (error) { } catch (error) {
console.error('Error saving note:', error); console.error('Error saving note:', error);
// TODO: Show error message to user // TODO: Show error message to user