diff --git a/frontend/app/view/preview.tsx b/frontend/app/view/preview.tsx index 32de511d1..90693287b 100644 --- a/frontend/app/view/preview.tsx +++ b/frontend/app/view/preview.tsx @@ -14,6 +14,39 @@ import "./view.less"; const MaxFileSize = 1024 * 1024 * 10; // 10MB +function DirNav({ cwdAtom }: { cwdAtom: jotai.WritableAtom }) { + const [cwd, setCwd] = jotai.useAtom(cwdAtom); + let splitNav = [cwd]; + let remaining = cwd; + + let idx = remaining.lastIndexOf("/"); + while (idx !== -1) { + remaining = remaining.substring(0, idx); + splitNav.unshift(remaining); + + idx = remaining.lastIndexOf("/"); + } + if (splitNav.length === 0) { + splitNav = [cwd]; + } + return ( +
+ {splitNav.map((item) => { + let splitPath = item.split("/"); + if (splitPath.length === 0) { + splitPath = [item]; + } + const baseName = splitPath[splitPath.length - 1]; + return ( + setCwd(item)}> + {baseName} + + ); + })} +
+ ); +} + function MarkdownPreview({ contentAtom }: { contentAtom: jotai.Atom> }) { const readmeText = jotai.useAtomValue(contentAtom); return ( @@ -119,31 +152,35 @@ function PreviewView({ blockId }: { blockId: string }) { const fileContent = jotai.useAtomValue(fileContentAtom); // handle streaming files here + let specializedView: React.ReactNode; if (mimeType.startsWith("video/") || mimeType.startsWith("audio/") || mimeType.startsWith("image/")) { - return ; - } - if (fileInfo == null) { - return File Not Found; - } - if (fileInfo.size > MaxFileSize) { - return File Too Large to Preview; - } - if (mimeType === "text/markdown") { - return ; - } - if (mimeType.startsWith("text/")) { - return ( + specializedView = ; + } else if (fileInfo == null) { + specializedView = File Not Found; + } else if (fileInfo.size > MaxFileSize) { + specializedView = File Too Large to Preview; + } else if (mimeType === "text/markdown") { + specializedView = ; + } else if (mimeType.startsWith("text/")) { + specializedView = (
{fileContent}
); + } else if (mimeType === "directory") { + specializedView = ; + } else { + specializedView = ( +
+
Preview ({mimeType})
+
+ ); } - if (mimeType === "directory") { - return ; - } + return ( -
-
Preview ({mimeType})
+
+ + {specializedView}
); } diff --git a/frontend/app/view/view.less b/frontend/app/view/view.less index d3e1ddc5f..2f6b2aca9 100644 --- a/frontend/app/view/view.less +++ b/frontend/app/view/view.less @@ -78,3 +78,27 @@ align-items: start; } } + +.full-preview { + display: flex; + flex-direction: column; +} + +.view-nav { + display: flex; + gap: 0.5rem; + + .view-nav-item { + background-color: var(--panel-bg-color); + border-radius: 3px; + padding: 0.2rem; + + &:hover { + background-color: var(--highlight-bg-color); + } + + &:active { + background-color: var(--accent-color); + } + } +}