diff --git a/src/components/layout/DocPreview.tsx b/src/components/layout/DocPreview.tsx index fc9d4f4..3eed70d 100644 --- a/src/components/layout/DocPreview.tsx +++ b/src/components/layout/DocPreview.tsx @@ -13,6 +13,7 @@ import { cjk } from "@streamdown/cjk"; import { code } from "@streamdown/code"; import { math } from "@streamdown/math"; import { mermaid } from "@streamdown/mermaid"; +import { usePanel } from "@/hooks/usePanel"; import type { FilePreview as FilePreviewType } from "@/types"; const streamdownPlugins = { cjk, code, math, mermaid }; @@ -52,6 +53,7 @@ export function DocPreview({ width, }: DocPreviewProps) { const { resolvedTheme } = useTheme(); + const { workingDirectory } = usePanel(); const isDark = resolvedTheme === "dark"; const [preview, setPreview] = useState(null); const [loading, setLoading] = useState(true); @@ -66,7 +68,7 @@ export function DocPreview({ setError(null); try { const res = await fetch( - `/api/files/preview?path=${encodeURIComponent(filePath)}&maxLines=500` + `/api/files/preview?path=${encodeURIComponent(filePath)}&maxLines=500${workingDirectory ? `&baseDir=${encodeURIComponent(workingDirectory)}` : ''}` ); if (!res.ok) { const data = await res.json(); diff --git a/src/components/project/FilePreview.tsx b/src/components/project/FilePreview.tsx index 60dcfac..a617ccf 100644 --- a/src/components/project/FilePreview.tsx +++ b/src/components/project/FilePreview.tsx @@ -8,6 +8,7 @@ import { Badge } from "@/components/ui/badge"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; import { atomOneDark } from "react-syntax-highlighter/dist/esm/styles/hljs"; +import { usePanel } from "@/hooks/usePanel"; import type { FilePreview as FilePreviewType } from "@/types"; interface FilePreviewProps { @@ -16,6 +17,7 @@ interface FilePreviewProps { } export function FilePreview({ filePath, onBack }: FilePreviewProps) { + const { workingDirectory } = usePanel(); const [preview, setPreview] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -27,7 +29,7 @@ export function FilePreview({ filePath, onBack }: FilePreviewProps) { setError(null); try { const res = await fetch( - `/api/files/preview?path=${encodeURIComponent(filePath)}` + `/api/files/preview?path=${encodeURIComponent(filePath)}${workingDirectory ? `&baseDir=${encodeURIComponent(workingDirectory)}` : ''}` ); if (!res.ok) { const data = await res.json();