Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

feat: add file tree component

nash_su7d9f6cb893ef
diff --git a/src/components/layout/file-tree.tsx b/src/components/layout/file-tree.tsx
new file mode 100644
index 00000000..209f69d7
--- /dev/null
+++ b/src/components/layout/file-tree.tsx
@@ -0,0 +1,78 @@
+import { useState } from "react"
+import { ChevronRight, ChevronDown, File, Folder } from "lucide-react"
+import { ScrollArea } from "@/components/ui/scroll-area"
+import { useWikiStore } from "@/stores/wiki-store"
+import type { FileNode } from "@/types/wiki"
+
+function TreeNode({ node, depth }: { node: FileNode; depth: number }) {
+ const [expanded, setExpanded] = useState(depth < 1)
+ const selectedFile = useWikiStore((s) => s.selectedFile)
+ const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
+
+ const isSelected = selectedFile === node.path
+ const paddingLeft = 12 + depth * 16
+
+ if (node.is_dir) {
+ return (
+ <div>
+ <button
+ onClick={() => setExpanded(!expanded)}
+ className="flex w-full items-center gap-1 py-1 text-sm text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"
+ style={{ paddingLeft }}
+ >
+ {expanded ? (
+ <ChevronDown className="h-3.5 w-3.5 shrink-0" />
+ ) : (
+ <ChevronRight className="h-3.5 w-3.5 shrink-0" />
+ )}
+ <Folder className="h-3.5 w-3.5 shrink-0 text-blue-400" />
+ <span className="truncate">{node.name}</span>
+ </button>
+ {expanded && node.children?.map((child) => (
+ <TreeNode key={child.path} node={child} depth={depth + 1} />
+ ))}
+ </div>
+ )
+ }
+
+ return (
+ <button
+ onClick={() => setSelectedFile(node.path)}
+ className={`flex w-full items-center gap-1 py-1 text-sm ${
+ isSelected
+ ? "bg-accent text-accent-foreground"
+ : "text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"
+ }`}
+ style={{ paddingLeft: paddingLeft + 14 }}
+ >
+ <File className="h-3.5 w-3.5 shrink-0" />
+ <span className="truncate">{node.name}</span>
+ </button>
+ )
+}
+
+export function FileTree() {
+ const fileTree = useWikiStore((s) => s.fileTree)
+ const project = useWikiStore((s) => s.project)
+
+ if (!project) {
+ return (
+ <div className="flex h-full items-center justify-center p-4 text-sm text-muted-foreground">
+ No project open
+ </div>
+ )
+ }
+
+ return (
+ <ScrollArea className="h-full">
+ <div className="p-2">
+ <div className="mb-2 px-2 text-xs font-semibold uppercase text-muted-foreground">
+ {project.name}
+ </div>
+ {fileTree.map((node) => (
+ <TreeNode key={node.path} node={node} depth={0} />
+ ))}
+ </div>
+ </ScrollArea>
+ )
+}