diff --git a/app/pages/page.tsx b/app/pages/page.tsx index 75173ca..16f38fa 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -303,13 +303,33 @@ export default function CarnetPage() { if (response.ok) { const data = await response.json(); - console.log(`Fetched ${data.length} notes from ${folderLowercase} folder`); + console.log(`Fetched ${data.length} files from ${folderLowercase} folder`, data); + + // Map API response to Note format + // API returns: { key, name, size, lastModified } + // Frontend expects: { id, title, content, lastModified, type, mime, etag } + const mappedNotes: Note[] = data.map((file: any) => { + // Extract title from filename (remove .md extension if present) + const title = file.name?.replace(/\.md$/, '') || file.name || 'Untitled'; + + return { + id: file.key || file.id || '', + title: title, + content: '', // Content will be loaded when note is selected + lastModified: file.lastModified ? new Date(file.lastModified).toISOString() : new Date().toISOString(), + type: 'file', + mime: file.name?.endsWith('.md') ? 'text/markdown' : 'text/plain', + etag: file.key || '' // Use key as etag for now + }; + }); + + console.log(`Mapped ${mappedNotes.length} notes from ${folderLowercase} folder`); // Update state - setNotes(data); + setNotes(mappedNotes); // Update cache - notesCache.set(cacheKey, data); + notesCache.set(cacheKey, mappedNotes); } else { const errorData = await response.json().catch(() => ({})); console.error('Error fetching notes:', errorData.message || response.statusText);