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) => {
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));
}}
/>
</div>

View File

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