From 20625b4596d4b9bad80241a7eb2f5aabb52ab600 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 17 Oct 2026 17:46:59 +0200 Subject: [PATCH] Stelle die Struktur als Hierarchie des gewaehlten Objekts dar und halte die Ordnerschrift im Postfach klein, ausser auf dem gewaehlten Pfad. Co-authored-by: Cursor --- frontend/src/pages/Sources.jsx | 11 +- frontend/src/pages/icons.jsx | 2 + frontend/src/pages/workspace.jsx | 218 +++++++++++++++++-------------- frontend/src/styles.css | 57 +++++--- 4 files changed, 170 insertions(+), 118 deletions(-) diff --git a/frontend/src/pages/Sources.jsx b/frontend/src/pages/Sources.jsx index cfbdec1..503d4e5 100644 --- a/frontend/src/pages/Sources.jsx +++ b/frontend/src/pages/Sources.jsx @@ -220,12 +220,14 @@ function ancestorNames(folders, name) { return names; } -function FolderBranch({ node, mailbox, expanded, onToggle, onSelect }) { +function FolderBranch({ node, mailbox, path, expanded, onToggle, onSelect }) { const open = expanded.has(node.name); const current = node.name === mailbox; + const onPath = path.has(node.name); + const rowClass = current ? "folder-row is-current" : onPath ? "folder-row is-ancestor" : "folder-row"; return (
  • -
    +
    {node.children.length ? ( + ); + } else if (node.href) { + row = ( + + {icon} + {label} + + ); + } else { + row = ( + + {icon} + {label} + + ); + } + if (node.moveUp === undefined && node.moveDown === undefined) return row; + return ( +
    + {row} + + + + +
    + ); +} + +function TreeNodes({ nodes, onNavigate, unfold = false }) { if (!nodes?.length) return null; return (
      - {nodes.map((node) => ( -
    • - {node.href ? ( - - - - {node.kind} - {node.title} - - - ) : ( - - - - {node.kind} - {node.title} - - - )} - {node.children?.length ? : null} -
    • - ))} + {nodes.map((node) => { + const open = unfold || node.current || branchHasCurrent(node); + return ( +
    • + + {open && node.children?.length ? ( + + ) : null} +
    • + ); + })}
    ); } +function scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter }) { + const items = []; + if (overview) { + items.push({ + id: "overview", + title: "Überblick", + kind: "Inhalte", + current: Boolean(overview.active), + onSelect: overview.onSelect, + }); + } + items.push({ + id: "all-contents", + title: allLabel, + kind: "Inhalte", + current: !chapterId && !overview?.active, + onSelect: () => onChapter?.(""), + }); + chapters.forEach((chapter, index) => { + items.push({ + id: chapter.id, + title: chapter.title, + kind: "Kapitel", + current: chapterId === chapter.id, + onSelect: () => onChapter?.(chapter.id), + ...(canReorder ? { + moveUp: index > 0 ? () => onMoveChapter(chapter.id, -1) : null, + moveDown: index < chapters.length - 1 ? () => onMoveChapter(chapter.id, 1) : null, + } : {}), + }); + }); + return items; +} + +function attachScope(nodes, extras) { + return (nodes || []).map((node) => { + const children = attachScope(node.children, extras); + if (!node.current) return { ...node, children }; + return { ...node, children: [...extras, ...children] }; + }); +} + +function treeWithScope(nodes, extras) { + const attached = attachScope(nodes, extras); + if (attached.some(branchHasCurrent)) return attached; + return [...extras, ...attached]; +} + export function StructureNavigator({ - contexts = [], - contextValue = "", - onContext, nodes = [], chapters = [], chapterId = "", - allCount = 0, allLabel = "Alle Inhalte", overview = null, - chapterHeading, onChapter, onAddChapter, canAddChapter = false, @@ -107,6 +186,7 @@ export function StructureNavigator({ onNavigate, onClose, }) { + const tree = treeWithScope(nodes, scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter })); return (