import React, { useEffect, useState } from 'react'; import { ChevronDown, ChevronRight, Folder, Link2 } from 'lucide-react'; import { Backlink } from '../../lib/types'; import { api } from '../../lib/api'; interface BacklinksSectionProps { docId: string; title: string; onOpen: (docId: string, blockId?: string) => void; } const COLLAPSED_KEY = 'mindsift:backlinks_collapsed'; // Shows the [[Wiki-Link]] parts of a block in the accent color, the rest as plain text const Snippet: React.FC<{ text: string }> = ({ text }) => ( <> {text.split(/(\[\[[^\]]*\]\])/g).map((part, i) => part.startsWith('[[') && part.endsWith(']]') ? ( {part} ) : ( {part} ) )} > ); // "Verlinkt auf diese Notiz" at the end of a note. Hidden while nothing links here; reloads shortly // after the title changes, since links are matched by title. export const BacklinksSection: React.FC = ({ docId, title, onOpen }) => { const [links, setLinks] = useState([]); const [collapsed, setCollapsed] = useState(() => { try { return localStorage.getItem(COLLAPSED_KEY) === 'true'; } catch { return false; } }); useEffect(() => { let cancelled = false; const timer = setTimeout(() => { api .getBacklinks(docId) .then((res) => !cancelled && setLinks(res)) .catch(() => !cancelled && setLinks([])); }, 400); return () => { cancelled = true; clearTimeout(timer); }; }, [docId, title]); if (links.length === 0) return null; const toggle = () => { setCollapsed((prev) => { try { localStorage.setItem(COLLAPSED_KEY, String(!prev)); } catch {} return !prev; }); }; return ( {collapsed ? : } Verlinkt auf diese Notiz ({links.length}) {!collapsed && ( {links.map((l) => ( onOpen(l.docId)} className="flex items-center gap-2 min-w-0 max-w-full text-left cursor-pointer group" > {l.icon || '📝'} {l.title || 'Unbenannte Notiz'} {l.folderPath && ( {l.folderPath} )} {l.blocks.map((b) => ( onOpen(l.docId, b.id)} className="w-full text-left text-xs text-muted hover:text-main px-2 py-1.5 rounded-btn hover:bg-panel-elevated border-l-2 border-border line-clamp-3 break-words cursor-pointer" > ))} {!!l.more && … und {l.more} weitere Stellen} ))} )} ); };
… und {l.more} weitere Stellen