diff --git a/frontend/app.js b/frontend/app.js index 70cd4cb..ff54173 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -379,6 +379,131 @@ function noteApp() { this.folderTree = { ...tree }; }, + // Render folder recursively (helper for deep nesting) + renderFolderRecursive(folder, level = 0, isTopLevel = false) { + if (!folder) return ''; + + let html = ''; + const isExpanded = this.expandedFolders.has(folder.path); + + // Render this folder's header + html += ` +
+
+
+ + + ${folder.name} + ${folder.notes.length === 0 && (!folder.children || Object.keys(folder.children).length === 0) ? '(empty)' : ''} + +
+
+ + + + +
+
+ `; + + // If expanded, render folder contents (child folders + notes) + if (isExpanded) { + html += `
`; + + // First, render child folders (if any) + if (folder.children && Object.keys(folder.children).length > 0) { + const children = Object.entries(folder.children).sort((a, b) => + a[1].name.toLowerCase().localeCompare(b[1].name.toLowerCase()) + ); + + children.forEach(([childKey, childFolder]) => { + html += this.renderFolderRecursive(childFolder, 0, false); + }); + } + + // Then, render notes in this folder (after subfolders) + if (folder.notes && folder.notes.length > 0) { + folder.notes.forEach(note => { + const isCurrentNote = this.currentNote === note.path; + html += ` +
+ ${note.name} + +
+ `; + }); + } + + html += `
`; // Close folder-contents + } + + html += `
`; // Close folder wrapper + return html; + }, + // Toggle folder expansion toggleFolder(folderPath) { if (this.expandedFolders.has(folderPath)) { @@ -386,6 +511,10 @@ function noteApp() { } else { this.expandedFolders.add(folderPath); } + // Force Alpine reactivity by creating new Set reference + this.expandedFolders = new Set(this.expandedFolders); + // Also trigger folderTree reactivity to re-render x-html + this.folderTree = { ...this.folderTree }; }, // Check if folder is expanded diff --git a/frontend/index.html b/frontend/index.html index 094bfbb..2db161c 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -687,201 +687,9 @@ - +