"use client"; import React, { useState, useEffect } from 'react'; import { Image, FileText, Link, List } from 'lucide-react'; interface Note { id: string; title: string; lastModified: string; size: number; type: string; mime: string; etag: string; content?: string; } interface EditorProps { note?: Note | null; onSave?: (note: Note) => void; } export const Editor: React.FC = ({ note, onSave }) => { const [title, setTitle] = useState(note?.title || ''); const [content, setContent] = useState(note?.content || ''); const [loading, setLoading] = useState(false); useEffect(() => { const fetchNoteContent = async () => { if (note?.id) { try { setLoading(true); const response = await fetch(`/api/nextcloud/files/${encodeURIComponent(note.id)}`); if (!response.ok) { throw new Error('Failed to fetch note content'); } const data = await response.json(); setContent(data.content || ''); } catch (err) { console.error('Error fetching note content:', err); } finally { setLoading(false); } } }; if (note) { setTitle(note.title); fetchNoteContent(); } else { setTitle(''); setContent(''); } }, [note]); const handleTitleChange = (e: React.ChangeEvent) => { setTitle(e.target.value); }; const handleContentChange = (e: React.ChangeEvent) => { setContent(e.target.value); }; const handleSave = () => { if (note?.id) { onSave?.({ ...note, title, content }); } }; return (
{/* Title Bar */}
{/* Toolbar */}
{/* Editor Area */}
{loading ? (
) : (