"use client"; import React, { useState, useEffect } from 'react'; import { Image, FileText, Link, List } from 'lucide-react'; interface Note { id: string; title: string; content: string; lastEdited: Date; category?: string; tags?: string[]; } interface EditorProps { note?: Note | null; onSave?: (note: Note) => void; currentFolder?: string; } export const Editor: React.FC = ({ note, onSave, currentFolder = 'Notes' }) => { const [title, setTitle] = useState(note?.title || ''); const [content, setContent] = useState(note?.content || ''); const [isSaving, setIsSaving] = useState(false); useEffect(() => { if (note) { setTitle(note.title); setContent(note.content); } }, [note]); const handleTitleChange = (e: React.ChangeEvent) => { setTitle(e.target.value); }; const handleContentChange = (e: React.ChangeEvent) => { setContent(e.target.value); }; const handleSave = async () => { if (!title || !content) return; setIsSaving(true); try { 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', }, body: JSON.stringify({ id: note?.id, title, content, folder: currentFolder }), }); if (!response.ok) { throw new Error('Failed to save note'); } const savedNote = await response.json(); onSave?.({ id: savedNote.id, title: savedNote.title, content, lastEdited: new Date(savedNote.lastModified), category: note?.category, tags: note?.tags }); } catch (error) { console.error('Error saving note:', error); // TODO: Show error message to user } finally { setIsSaving(false); } }; return (
{/* Title Bar */}
{/* Toolbar */}
{/* Editor Area */}