From b675e8677ca4416ff08254cb2f962f1f09fcd47e Mon Sep 17 00:00:00 2001 From: Michael Ramos Date: Mon, 23 Mar 2026 15:47:58 -0700 Subject: [PATCH] feat: markdown file browser sidebar tab (#378) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: markdown file browser sidebar tab (#367) Add a Files sidebar tab that lets users browse and annotate markdown files from their project. The project root is shown automatically — no configuration needed. Users can add extra directories in Settings. - Server: new /api/reference/files endpoint scans directories for .md files with broad exclusion list (node_modules, .git, dist, etc.) - Server: projectRoot sent in /api/plan response (plan + annotate) - UI: FileBrowser component with per-directory collapsible sections - UI: useFileBrowser hook manages multi-directory tree state - UI: Files tab in sidebar (collapsed + expanded), between Versions and Vault - UI: Settings integration tab for additional directories - Wired into linked doc system for annotation support Closes #367 For provenance purposes, this commit was AI assisted. * fix: simplify file browser - compute activeDirPath, fix re-fetch bug, dedupe settings logic - Compute activeDirPath from activeFile + dirs instead of storing as separate state (removes state setter hack that abused setDirs as a read accessor) - Fix auto-fetch not detecting directory changes: compare loaded paths against configured dirs instead of checking dirs.length === 0 - Extract addDirectory() helper in Settings to eliminate copy-pasted trim-validate-add-clear logic - Remove "what" comments that described obvious code For provenance purposes, this commit was AI assisted. * fix: file browser prefix match, settings reactivity, and vault→files routing - Add trailing slash to activeDirPath startsWith check to prevent prefix collisions - Spread uiPrefs in handleFileBrowserChange so React sees a new reference on each settings edit - Clear vaultBrowser.activeFile when opening a file browser doc to prevent misrouted links For provenance purposes, this commit was AI assisted. --- packages/editor/App.tsx | 66 +++++- packages/server/annotate.ts | 8 +- packages/server/index.ts | 9 +- packages/server/reference-handlers.ts | 40 +++- packages/ui/components/Settings.tsx | 122 +++++++++- .../ui/components/sidebar/FileBrowser.tsx | 209 ++++++++++++++++++ .../components/sidebar/SidebarContainer.tsx | 45 ++++ .../ui/components/sidebar/SidebarTabs.tsx | 25 +++ packages/ui/hooks/useFileBrowser.ts | 138 ++++++++++++ packages/ui/hooks/useSidebar.ts | 2 +- packages/ui/utils/fileBrowser.ts | 40 ++++ 11 files changed, 689 insertions(+), 15 deletions(-) create mode 100644 packages/ui/components/sidebar/FileBrowser.tsx create mode 100644 packages/ui/hooks/useFileBrowser.ts create mode 100644 packages/ui/utils/fileBrowser.ts diff --git a/packages/editor/App.tsx b/packages/editor/App.tsx index 13b04b2..b95bee0 100644 --- a/packages/editor/App.tsx +++ b/packages/editor/App.tsx @@ -46,7 +46,9 @@ import { useVaultBrowser } from '@plannotator/ui/hooks/useVaultBrowser'; import { useAnnotationDraft } from '@plannotator/ui/hooks/useAnnotationDraft'; import { useArchive } from '@plannotator/ui/hooks/useArchive'; import { useEditorAnnotations } from '@plannotator/ui/hooks/useEditorAnnotations'; +import { useFileBrowser } from '@plannotator/ui/hooks/useFileBrowser'; import { isVaultBrowserEnabled } from '@plannotator/ui/utils/obsidian'; +import { isFileBrowserEnabled, getFileBrowserSettings } from '@plannotator/ui/utils/fileBrowser'; import { SidebarTabs } from '@plannotator/ui/components/sidebar/SidebarTabs'; import { SidebarContainer } from '@plannotator/ui/components/sidebar/SidebarContainer'; import type { ArchivedPlan } from '@plannotator/ui/components/sidebar/ArchiveBrowser'; @@ -97,6 +99,7 @@ const App: React.FC = () => { const [shareBaseUrl, setShareBaseUrl] = useState(undefined); const [pasteApiUrl, setPasteApiUrl] = useState(undefined); const [repoInfo, setRepoInfo] = useState<{ display: string; branch?: string } | null>(null); + const [projectRoot, setProjectRoot] = useState(null); useEffect(() => { document.title = repoInfo ? `${repoInfo.display} · Plannotator` : "Plannotator"; @@ -205,10 +208,52 @@ const App: React.FC = () => { vaultBrowser.setActiveFile(relativePath); }, [vaultPath, linkedDocHook, vaultBrowser, buildVaultDocUrl]); - // Route linked doc opens through vault endpoint when viewing a vault file + // Markdown file browser + const fileBrowser = useFileBrowser(); + const showFilesTab = useMemo(() => !!projectRoot || isFileBrowserEnabled(), [projectRoot, uiPrefs]); + const fileBrowserDirs = useMemo(() => { + const projectDirs = projectRoot ? [projectRoot] : []; + const userDirs = isFileBrowserEnabled() + ? getFileBrowserSettings().directories + : []; + return [...new Set([...projectDirs, ...userDirs])]; + }, [projectRoot, uiPrefs]); + + // Clear active file when file browser is disabled + useEffect(() => { + if (!showFilesTab) fileBrowser.setActiveFile(null); + }, [showFilesTab]); + + useEffect(() => { + if (sidebar.activeTab === 'files' && showFilesTab && fileBrowserDirs.length > 0) { + const loadedPaths = fileBrowser.dirs.map((d) => d.path); + const needsFetch = fileBrowserDirs.length !== loadedPaths.length + || fileBrowserDirs.some((d) => !loadedPaths.includes(d)); + if (needsFetch) { + fileBrowser.fetchAll(fileBrowserDirs); + } + } + }, [sidebar.activeTab, showFilesTab, fileBrowserDirs]); + + // File browser file selection: open via linked doc system + const handleFileBrowserSelect = React.useCallback((absolutePath: string, dirPath: string) => { + const buildUrl = (path: string) => + `/api/doc?path=${encodeURIComponent(path)}&base=${encodeURIComponent(dirPath)}`; + linkedDocHook.open(absolutePath, buildUrl, 'files'); + fileBrowser.setActiveFile(absolutePath); + vaultBrowser.setActiveFile(null); + }, [linkedDocHook, fileBrowser]); + + // Route linked doc opens through vault/file browser endpoint when viewing one of those files const handleOpenLinkedDoc = React.useCallback((docPath: string) => { if (vaultBrowser.activeFile && vaultPath) { linkedDocHook.open(docPath, buildVaultDocUrl(vaultPath)); + } else if (fileBrowser.activeFile && fileBrowser.activeDirPath) { + // When viewing a file browser doc, resolve links relative to current file's directory + const baseDir = linkedDocHook.filepath?.replace(/\/[^/]+$/, '') || fileBrowser.activeDirPath; + linkedDocHook.open(docPath, (path) => + `/api/doc?path=${encodeURIComponent(path)}&base=${encodeURIComponent(baseDir)}` + ); } else { // Pass the current file's directory as base for relative path resolution const baseDir = linkedDocHook.filepath @@ -222,14 +267,15 @@ const App: React.FC = () => { linkedDocHook.open(docPath); } } - }, [vaultBrowser.activeFile, vaultPath, linkedDocHook, buildVaultDocUrl, imageBaseDir]); + }, [vaultBrowser.activeFile, vaultPath, fileBrowser.activeFile, fileBrowser.activeDirPath, linkedDocHook, buildVaultDocUrl, imageBaseDir]); - // Wrap linked doc back to also clear vault active file + // Wrap linked doc back to also clear vault/file browser active file const handleLinkedDocBack = React.useCallback(() => { linkedDocHook.back(); vaultBrowser.setActiveFile(null); + fileBrowser.setActiveFile(null); archive.clearSelection(); - }, [linkedDocHook, vaultBrowser, archive]); + }, [linkedDocHook, vaultBrowser, fileBrowser, archive]); const handleVaultFetchTree = React.useCallback(() => { vaultBrowser.fetchTree(vaultPath); @@ -339,7 +385,7 @@ const App: React.FC = () => { if (!res.ok) throw new Error('Not in API mode'); return res.json(); }) - .then((data: { plan: string; origin?: 'claude-code' | 'opencode' | 'pi' | 'codex'; mode?: 'annotate' | 'annotate-last' | 'archive'; filePath?: string; sharingEnabled?: boolean; shareBaseUrl?: string; pasteApiUrl?: string; repoInfo?: { display: string; branch?: string }; previousPlan?: string | null; versionInfo?: { version: number; totalVersions: number; project: string }; archivePlans?: ArchivedPlan[] }) => { + .then((data: { plan: string; origin?: 'claude-code' | 'opencode' | 'pi' | 'codex'; mode?: 'annotate' | 'annotate-last' | 'archive'; filePath?: string; sharingEnabled?: boolean; shareBaseUrl?: string; pasteApiUrl?: string; repoInfo?: { display: string; branch?: string }; previousPlan?: string | null; versionInfo?: { version: number; totalVersions: number; project: string }; archivePlans?: ArchivedPlan[]; projectRoot?: string }) => { if (data.mode === 'archive') { // Archive mode: show first archived plan or clear demo content setMarkdown(data.plan || ''); @@ -371,6 +417,9 @@ const App: React.FC = () => { if (data.repoInfo) { setRepoInfo(data.repoInfo); } + if (data.projectRoot) { + setProjectRoot(data.projectRoot); + } // Capture plan version history data if (data.previousPlan !== undefined) { setPreviousPlan(data.previousPlan); @@ -1244,6 +1293,7 @@ const App: React.FC = () => { activeTab={sidebar.activeTab} onToggleTab={sidebar.toggleTab} hasDiff={planDiff.hasPreviousVersion} + showFilesTab={showFilesTab && !archive.archiveMode} showVaultTab={showVaultTab} className="hidden lg:flex" /> @@ -1266,6 +1316,10 @@ const App: React.FC = () => { onTocNavigate={handleTocNavigate} linkedDocFilepath={linkedDocHook.filepath} onLinkedDocBack={linkedDocHook.isActive ? handleLinkedDocBack : undefined} + showFilesTab={showFilesTab && !archive.archiveMode} + fileBrowser={fileBrowser} + onFilesSelectFile={handleFileBrowserSelect} + onFilesFetchAll={() => fileBrowser.fetchAll(fileBrowserDirs)} showVaultTab={showVaultTab && !archive.archiveMode} vaultPath={vaultPath} vaultBrowser={vaultBrowser} @@ -1366,7 +1420,7 @@ const App: React.FC = () => { showDemoBadge={!isApiMode && !isLoadingShared && !isSharedSession} maxWidth={planMaxWidth} onOpenLinkedDoc={handleOpenLinkedDoc} - linkedDocInfo={linkedDocHook.isActive ? { filepath: linkedDocHook.filepath!, onBack: handleLinkedDocBack, label: vaultBrowser.activeFile ? 'Vault File' : undefined } : null} + linkedDocInfo={linkedDocHook.isActive ? { filepath: linkedDocHook.filepath!, onBack: handleLinkedDocBack, label: vaultBrowser.activeFile ? 'Vault File' : fileBrowser.activeFile ? 'File' : undefined } : null} imageBaseDir={imageBaseDir} copyLabel={annotateSource === 'message' ? 'Copy message' : annotateSource === 'file' ? 'Copy file' : undefined} archiveInfo={archive.currentInfo} diff --git a/packages/server/annotate.ts b/packages/server/annotate.ts index 6413f25..3c7a9dc 100644 --- a/packages/server/annotate.ts +++ b/packages/server/annotate.ts @@ -14,7 +14,7 @@ import { isRemoteSession, getServerPort } from "./remote"; import { getRepoInfo } from "./repo"; import { handleImage, handleUpload, handleServerReady, handleDraftSave, handleDraftLoad, handleDraftDelete, handleFavicon } from "./shared-handlers"; -import { handleDoc } from "./reference-handlers"; +import { handleDoc, handleFileBrowserFiles } from "./reference-handlers"; import { contentHash, deleteDraft } from "./draft"; import { dirname } from "path"; @@ -127,6 +127,7 @@ export async function startAnnotateServer( sharingEnabled, shareBaseUrl, repoInfo, + projectRoot: process.cwd(), }); } @@ -146,6 +147,11 @@ export async function startAnnotateServer( return handleDoc(req); } + // API: List markdown files in a directory as a tree + if (url.pathname === "/api/reference/files" && req.method === "GET") { + return handleFileBrowserFiles(req); + } + // API: Upload image -> save to temp -> return path if (url.pathname === "/api/upload" && req.method === "POST") { return handleUpload(req); diff --git a/packages/server/index.ts b/packages/server/index.ts index c4d51a0..38d1eeb 100644 --- a/packages/server/index.ts +++ b/packages/server/index.ts @@ -39,7 +39,7 @@ import { getRepoInfo } from "./repo"; import { detectProjectName } from "./project"; import { handleImage, handleUpload, handleAgents, handleServerReady, handleDraftSave, handleDraftLoad, handleDraftDelete, handleFavicon, type OpencodeClient } from "./shared-handlers"; import { contentHash, deleteDraft } from "./draft"; -import { handleDoc, handleObsidianVaults, handleObsidianFiles, handleObsidianDoc } from "./reference-handlers"; +import { handleDoc, handleObsidianVaults, handleObsidianFiles, handleObsidianDoc, handleFileBrowserFiles } from "./reference-handlers"; import { createEditorAnnotationHandler } from "./editor-annotations"; // Re-export utilities @@ -264,7 +264,7 @@ export async function startPlannotatorServer( shareBaseUrl, }); } - return Response.json({ plan, origin, permissionMode, sharingEnabled, shareBaseUrl, pasteApiUrl, repoInfo, previousPlan, versionInfo }); + return Response.json({ plan, origin, permissionMode, sharingEnabled, shareBaseUrl, pasteApiUrl, repoInfo, previousPlan, versionInfo, projectRoot: process.cwd() }); } // API: Serve a linked markdown document @@ -322,6 +322,11 @@ export async function startPlannotatorServer( return handleObsidianDoc(req); } + // API: List markdown files in a directory as a tree + if (url.pathname === "/api/reference/files" && req.method === "GET") { + return handleFileBrowserFiles(req); + } + // API: Get available agents (OpenCode only) if (url.pathname === "/api/agents") { return handleAgents(options.opencodeClient); diff --git a/packages/server/reference-handlers.ts b/packages/server/reference-handlers.ts index e2bdd24..41191fe 100644 --- a/packages/server/reference-handlers.ts +++ b/packages/server/reference-handlers.ts @@ -2,7 +2,7 @@ * Reference/document route handlers for the plan server. * * Handles /api/doc, /api/obsidian/vaults, /api/reference/obsidian/files, - * and /api/reference/obsidian/doc. Extracted from index.ts for modularity. + * /api/reference/obsidian/doc, and /api/reference/files. Extracted from index.ts for modularity. */ import { existsSync, statSync } from "fs"; @@ -194,3 +194,41 @@ export async function handleObsidianDoc(req: Request): Promise { return Response.json({ error: "Failed to read file" }, { status: 500 }); } } + +// --- File Browser --- + +const FILE_BROWSER_EXCLUDED = [ + "node_modules/", ".git/", "dist/", "build/", ".next/", + "__pycache__/", ".obsidian/", ".trash/", ".venv/", "vendor/", + "target/", ".cache/", "coverage/", ".turbo/", ".svelte-kit/", + ".nuxt/", ".output/", ".parcel-cache/", ".webpack/", ".expo/", +]; + +/** List markdown files in a directory as a nested tree. */ +export async function handleFileBrowserFiles(req: Request): Promise { + const url = new URL(req.url); + const dirPath = url.searchParams.get("dirPath"); + if (!dirPath) { + return Response.json({ error: "Missing dirPath parameter" }, { status: 400 }); + } + + const resolvedDir = resolve(dirPath); + if (!existsSync(resolvedDir) || !statSync(resolvedDir).isDirectory()) { + return Response.json({ error: "Invalid directory path" }, { status: 400 }); + } + + try { + const glob = new Bun.Glob("**/*.md"); + const files: string[] = []; + for await (const match of glob.scan({ cwd: resolvedDir, onlyFiles: true })) { + if (FILE_BROWSER_EXCLUDED.some((dir) => match.includes(dir))) continue; + files.push(match); + } + files.sort(); + + const tree = buildFileTree(files); + return Response.json({ tree }); + } catch { + return Response.json({ error: "Failed to list directory files" }, { status: 500 }); + } +} diff --git a/packages/ui/components/Settings.tsx b/packages/ui/components/Settings.tsx index f89cecd..f123d79 100644 --- a/packages/ui/components/Settings.tsx +++ b/packages/ui/components/Settings.tsx @@ -59,8 +59,13 @@ import { ThemeTab } from './ThemeTab'; import { isMac, modKey, altKey } from '../utils/platform'; import { getAIProviderSettings } from '../utils/aiProvider'; import { AISettingsTab } from './AISettingsTab'; +import { + getFileBrowserSettings, + saveFileBrowserSettings, + type FileBrowserSettings, +} from '../utils/fileBrowser'; -type SettingsTab = 'general' | 'theme' | 'display' | 'saving' | 'labels' | 'shortcuts' | 'ai' | 'obsidian' | 'bear' | 'octarine'; +type SettingsTab = 'general' | 'theme' | 'display' | 'saving' | 'labels' | 'shortcuts' | 'ai' | 'files' | 'obsidian' | 'bear' | 'octarine'; interface SettingsProps { taterMode: boolean; @@ -102,6 +107,8 @@ export const Settings: React.FC = ({ taterMode, onTaterModeChange const [editingTipValue, setEditingTipValue] = useState(''); const [showNewHints, setShowNewHints] = useState(() => hasNewSettings()); const [aiProvider, setAiProvider] = useState(null); + const [fileBrowserSettings, setFileBrowserSettings] = useState({ enabled: false, directories: [] }); + const [newDirPath, setNewDirPath] = useState(''); // Fetch available agents for OpenCode const { agents: availableAgents, validateAgent, getAgentWarning } = useAgents(origin ?? null); @@ -121,9 +128,12 @@ export const Settings: React.FC = ({ taterMode, onTaterModeChange return t; }, [mode, aiProviders.length]); - const integrationTabs: { id: SettingsTab; label: string }[] = mode === 'plan' - ? [{ id: 'obsidian', label: 'Obsidian' }, { id: 'bear', label: 'Bear' }, { id: 'octarine', label: 'Octarine' }] - : []; + const integrationTabs: { id: SettingsTab; label: string }[] = [ + { id: 'files', label: 'Files' }, + ...(mode === 'plan' + ? [{ id: 'obsidian' as SettingsTab, label: 'Obsidian' }, { id: 'bear' as SettingsTab, label: 'Bear' }, { id: 'octarine' as SettingsTab, label: 'Octarine' }] + : []), + ]; const obsidianDefaultSaveAvailable = obsidian.enabled && getEffectiveVaultPath(obsidian).trim().length > 0; const bearDefaultSaveAvailable = bear.enabled; const octarineDefaultSaveAvailable = octarine.enabled && octarine.workspace.trim().length > 0; @@ -151,6 +161,7 @@ export const Settings: React.FC = ({ taterMode, onTaterModeChange setDefaultNotesApp(getDefaultNotesApp()); setQuickLabelsState(getQuickLabels()); setAiProvider(getAIProviderSettings().providerId); + setFileBrowserSettings(getFileBrowserSettings()); // Validate agent setting when dialog opens if (origin === 'opencode') { @@ -199,6 +210,23 @@ export const Settings: React.FC = ({ taterMode, onTaterModeChange } }, [obsidian.enabled]); + const handleFileBrowserChange = (updates: Partial) => { + const newSettings = { ...fileBrowserSettings, ...updates }; + setFileBrowserSettings(newSettings); + saveFileBrowserSettings(newSettings); + if (onUIPreferencesChange) onUIPreferencesChange({ ...uiPrefs }); + }; + + const addDirectory = () => { + const trimmed = newDirPath.trim(); + if (trimmed && !fileBrowserSettings.directories.includes(trimmed)) { + handleFileBrowserChange({ + directories: [...fileBrowserSettings.directories, trimmed], + }); + } + setNewDirPath(''); + }; + const handleObsidianChange = (updates: Partial) => { const newSettings = { ...obsidian, ...updates }; setObsidian(newSettings); @@ -1039,6 +1067,92 @@ export const Settings: React.FC = ({ taterMode, onTaterModeChange /> )} + {/* === FILES TAB === */} + {activeTab === 'files' && ( + <> +
+
+
File Browser
+
+ Your project files are shown automatically. Add extra directories below. +
+
+ +
+ + {fileBrowserSettings.enabled && ( + <> +
+ + {/* Directory list */} + {fileBrowserSettings.directories.length > 0 && ( +
+ + {fileBrowserSettings.directories.map((dir) => ( +
+
+ {dir} +
+ +
+ ))} +
+ )} + + {/* Add directory */} +
+ +
+ setNewDirPath(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') addDirectory(); + }} + placeholder="/path/to/directory" + className="flex-1 px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50" + /> + +
+
+ Add directories outside your project that contain markdown files. +
+
+ + )} + + )} + {/* === OBSIDIAN TAB === */} {activeTab === 'obsidian' && ( <> diff --git a/packages/ui/components/sidebar/FileBrowser.tsx b/packages/ui/components/sidebar/FileBrowser.tsx new file mode 100644 index 0000000..b277612 --- /dev/null +++ b/packages/ui/components/sidebar/FileBrowser.tsx @@ -0,0 +1,209 @@ +/** + * FileBrowser — Markdown file tree for the sidebar + * + * Displays collapsible trees of markdown files from user-configured directories. + * Clicking a file opens it in the main viewer for annotation. + */ + +import React from "react"; +import type { VaultNode } from "../../types"; +import type { DirState } from "../../hooks/useFileBrowser"; + +interface FileBrowserProps { + dirs: DirState[]; + expandedFolders: Set; + onToggleFolder: (key: string) => void; + collapsedDirs: Set; + onToggleCollapse: (dirPath: string) => void; + onSelectFile: (absolutePath: string, dirPath: string) => void; + activeFile: string | null; + onFetchAll: () => void; +} + +const TreeNode: React.FC<{ + node: VaultNode; + depth: number; + dirPath: string; + expandedFolders: Set; + onToggleFolder: (key: string) => void; + onSelectFile: (absolutePath: string, dirPath: string) => void; + activeFile: string | null; +}> = ({ node, depth, dirPath, expandedFolders, onToggleFolder, onSelectFile, activeFile }) => { + const folderKey = `${dirPath}:${node.path}`; + const absolutePath = `${dirPath}/${node.path}`; + const isExpanded = expandedFolders.has(folderKey); + const isActive = node.type === "file" && absolutePath === activeFile; + const paddingLeft = 8 + depth * 14; + + if (node.type === "folder") { + return ( + <> + + {isExpanded && node.children?.map((child) => ( + + ))} + + ); + } + + const displayName = node.name.replace(/\.mdx?$/i, ""); + return ( + + ); +}; + +const DirSection: React.FC<{ + dir: DirState; + expandedFolders: Set; + onToggleFolder: (key: string) => void; + onSelectFile: (absolutePath: string, dirPath: string) => void; + activeFile: string | null; + onRetry: () => void; +}> = ({ dir, expandedFolders, onToggleFolder, onSelectFile, activeFile, onRetry }) => { + if (dir.isLoading) { + return ( +
+ Loading... +
+ ); + } + + if (dir.error) { + return ( +
+
{dir.error}
+ +
+ ); + } + + if (dir.tree.length === 0) { + return ( +
+ No markdown files found +
+ ); + } + + return ( +
+ {dir.tree.map((node) => ( + + ))} +
+ ); +}; + +export const FileBrowser: React.FC = ({ + dirs, + expandedFolders, + onToggleFolder, + collapsedDirs, + onToggleCollapse, + onSelectFile, + activeFile, + onFetchAll, +}) => { + if (dirs.length === 0) { + return ( +
+ No directories configured. Add directories in Settings → Files. +
+ ); + } + + return ( +
+ {dirs.map((dir) => { + const isCollapsed = collapsedDirs.has(dir.path); + return ( +
+ + {!isCollapsed && ( + + )} +
+ ); + })} +
+ ); +}; diff --git a/packages/ui/components/sidebar/SidebarContainer.tsx b/packages/ui/components/sidebar/SidebarContainer.tsx index 6654649..0f012a2 100644 --- a/packages/ui/components/sidebar/SidebarContainer.tsx +++ b/packages/ui/components/sidebar/SidebarContainer.tsx @@ -10,9 +10,11 @@ import type { SidebarTab } from "../../hooks/useSidebar"; import type { Block, Annotation } from "../../types"; import type { VersionInfo, VersionEntry } from "../../hooks/usePlanDiff"; import type { UseVaultBrowserReturn } from "../../hooks/useVaultBrowser"; +import type { UseFileBrowserReturn } from "../../hooks/useFileBrowser"; import { TableOfContents } from "../TableOfContents"; import { VersionBrowser } from "./VersionBrowser"; import { VaultBrowser } from "./VaultBrowser"; +import { FileBrowser } from "./FileBrowser"; import { ArchiveBrowser, type ArchivedPlan } from "./ArchiveBrowser"; interface SidebarContainerProps { @@ -27,6 +29,11 @@ interface SidebarContainerProps { onTocNavigate: (blockId: string) => void; linkedDocFilepath?: string | null; onLinkedDocBack?: () => void; + // File Browser props + showFilesTab?: boolean; + fileBrowser?: UseFileBrowserReturn; + onFilesSelectFile?: (absolutePath: string, dirPath: string) => void; + onFilesFetchAll?: () => void; // Vault Browser props showVaultTab?: boolean; vaultPath?: string; @@ -64,6 +71,10 @@ export const SidebarContainer: React.FC = ({ onTocNavigate, linkedDocFilepath, onLinkedDocBack, + showFilesTab, + fileBrowser, + onFilesSelectFile, + onFilesFetchAll, showVaultTab, vaultPath, vaultBrowser, @@ -133,6 +144,28 @@ export const SidebarContainer: React.FC = ({ } label="Versions" /> + {showFilesTab && ( + onTabChange("files")} + icon={ + + + + } + label="Files" + /> + )} {showVaultTab && ( = ({ onFetchVersions={onFetchVersions} /> )} + {activeTab === "files" && showFilesTab && fileBrowser && ( + {})} + activeFile={fileBrowser.activeFile} + onFetchAll={onFilesFetchAll ?? (() => {})} + /> + )} {activeTab === "vault" && showVaultTab && vaultPath && vaultBrowser && ( void; hasDiff: boolean; + showFilesTab?: boolean; showVaultTab?: boolean; className?: string; } @@ -20,6 +21,7 @@ export const SidebarTabs: React.FC = ({ activeTab, onToggleTab, hasDiff, + showFilesTab, showVaultTab, className, }) => { @@ -73,6 +75,29 @@ export const SidebarTabs: React.FC = ({ )} + {/* Files tab */} + {showFilesTab && ( + + )} + {/* Vault tab */} {showVaultTab && (