mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Add comprehensive documentation and download feature (#83)
* fix: markdown files now default to rendered view and render properly - Add .md and .mdx MIME type support in backend (files.ts, defaults.ts) - Add key props to FilePreview components to force proper remounting when switching files - Fix markdown file detection with case-insensitive extension check - Reset markdownPreview state when file changes to ensure correct default view - Add onContentLoaded callback to VirtualizedTextView for reactive content updates - Add fullContent state to properly handle large markdown file rendering - Add error handling for async content loading to prevent blank screens - Reduce loading timeout from 50ms to 0ms for more responsive loading Fixes issues where: - Markdown files opened in raw view instead of rendered view - Large markdown files (12k+ lines) showed blank after loading completed - State persisted incorrectly when switching between different file types * Add directory download feature with ZIP archive support * Improve voice recording UX with loading states and better transcript handling * Fix auth config for prod/dev ports and add documentation Update AUTH_TRUSTED_ORIGINS and PASSKEY_ORIGIN to use backend port 5003 (frontend uses 5173 in dev). Add comprehensive auth documentation covering secrets, trusted origins, admin reset, and passkeys. Update README and add mkdocs config. * Remove roadmap section from README
This commit is contained in:
1 parent
358abbf20e
commit
da6cad8b3a
51 files changed
+4276
-353
No files matched your search
@@ -534,7 +534,7 @@ useEffect(() => {
|
||||
{!isMobile && (
|
||||
<div className="flex-1 overflow-y-auto min-h-0 h-full">
|
||||
{selectedFile && !selectedFile.isDirectory ? (
|
||||
<FilePreview file={selectedFile} />
|
||||
<FilePreview key={selectedFile.path} file={selectedFile} />
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-full text-muted-foreground">
|
||||
Select a file to preview
|
||||
@@ -633,7 +633,7 @@ useEffect(() => {
|
||||
{!isMobile && (
|
||||
<div className="flex-1 overflow-y-auto min-h-0 ">
|
||||
{selectedFile && !selectedFile.isDirectory ? (
|
||||
<FilePreview file={selectedFile} />
|
||||
<FilePreview key={selectedFile.path} file={selectedFile} />
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-64 text-muted-foreground">
|
||||
Select a file to preview
|
||||
|
||||
@@ -3,23 +3,35 @@ import { FileBrowser } from './FileBrowser'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { PathDisplay } from '@/components/ui/path-display'
|
||||
import { FullscreenSheet, FullscreenSheetHeader, FullscreenSheetContent } from '@/components/ui/fullscreen-sheet'
|
||||
import { X } from 'lucide-react'
|
||||
import { DownloadDialog } from '@/components/ui/download-dialog'
|
||||
import { X, Download } from 'lucide-react'
|
||||
import { GPU_ACCELERATED_STYLE, MODAL_TRANSITION_MS } from '@/lib/utils'
|
||||
import { useSwipeBack } from '@/hooks/useMobile'
|
||||
import { downloadDirectoryAsZip } from '@/api/files'
|
||||
import { downloadRepo } from '@/api/repos'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
|
||||
interface FileBrowserSheetProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
basePath?: string
|
||||
repoName?: string
|
||||
repoId?: number
|
||||
initialSelectedFile?: string
|
||||
}
|
||||
|
||||
export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose, basePath = '', repoName, initialSelectedFile }: FileBrowserSheetProps) {
|
||||
export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose, basePath = '', repoName, repoId, initialSelectedFile }: FileBrowserSheetProps) {
|
||||
const normalizedBasePath = basePath || '.'
|
||||
const [isEditing, setIsEditing] = useState(false)
|
||||
const [displayPath, setDisplayPath] = useState<string>('/')
|
||||
const [shouldRender, setShouldRender] = useState(false)
|
||||
const [currentPath, setCurrentPath] = useState<string>(basePath || '.')
|
||||
const [downloadDialog, setDownloadDialog] = useState<{ type: 'directory' | 'repository' } | null>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const { bind, swipeStyles } = useSwipeBack(onClose, {
|
||||
@@ -42,11 +54,14 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
const handleDirectoryLoad = useCallback((info: { workspaceRoot?: string; currentPath: string }) => {
|
||||
if (!info.currentPath || info.currentPath === '.' || info.currentPath === '') {
|
||||
setDisplayPath('/')
|
||||
setCurrentPath(basePath || '.')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
setCurrentPath(info.currentPath)
|
||||
|
||||
const pathParts = info.currentPath.split('/').filter(Boolean)
|
||||
|
||||
|
||||
if (repoName) {
|
||||
const repoIndex = pathParts.findIndex(p => p === repoName || p.startsWith(repoName + '-'))
|
||||
if (repoIndex >= 0) {
|
||||
@@ -58,7 +73,21 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
} else {
|
||||
setDisplayPath('/' + pathParts.join('/'))
|
||||
}
|
||||
}, [repoName])
|
||||
}, [repoName, basePath])
|
||||
|
||||
const handleDownloadDirectory = useCallback(async () => {
|
||||
if (!currentPath) return
|
||||
await downloadDirectoryAsZip(currentPath)
|
||||
}, [currentPath])
|
||||
|
||||
const handleDownloadRepo = useCallback(async () => {
|
||||
if (!repoId || !repoName) return
|
||||
await downloadRepo(repoId, repoName)
|
||||
}, [repoId, repoName])
|
||||
|
||||
const handleOpenDownloadDialog = (type: 'directory' | 'repository') => {
|
||||
setDownloadDialog({ type })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const handleEscape = (e: KeyboardEvent) => {
|
||||
@@ -98,30 +127,55 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
>
|
||||
<FullscreenSheet style={{ ...GPU_ACCELERATED_STYLE, ...swipeStyles }}>
|
||||
<FullscreenSheetHeader className="px-4 py-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
{(displayPath === '/' || !repoName) && (
|
||||
<h1 className="text-sm font-semibold text-foreground">
|
||||
{repoName || 'Workspace Files'}
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2 min-w-0 flex-1 overflow-hidden">
|
||||
{(displayPath === '/' || !repoName) && repoName && (
|
||||
<h1 className="text-sm font-semibold text-foreground shrink-0 truncate max-w-[150px]">
|
||||
{repoName}
|
||||
</h1>
|
||||
)}
|
||||
<PathDisplay path={displayPath} maxSegments={3} />
|
||||
<PathDisplay path={displayPath} maxSegments={2} className="truncate" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{repoId && !isEditing && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-muted transition-all duration-200"
|
||||
>
|
||||
<Download className="w-5 h-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => handleOpenDownloadDialog('directory')}>
|
||||
<Download className="w-4 h-4 mr-2" />
|
||||
Current Directory
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => handleOpenDownloadDialog('repository')}>
|
||||
<Download className="w-4 h-4 mr-2" />
|
||||
Entire Repository
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
{!isEditing && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onClose}
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-muted transition-all duration-200"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{!isEditing && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onClose}
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-muted transition-all duration-200"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</FullscreenSheetHeader>
|
||||
|
||||
<FullscreenSheetContent>
|
||||
<FileBrowser
|
||||
<FileBrowser
|
||||
basePath={normalizedBasePath}
|
||||
embedded={true}
|
||||
initialSelectedFile={initialSelectedFile}
|
||||
@@ -129,6 +183,17 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
/>
|
||||
</FullscreenSheetContent>
|
||||
</FullscreenSheet>
|
||||
|
||||
<DownloadDialog
|
||||
open={downloadDialog !== null}
|
||||
onOpenChange={(open) => !open && setDownloadDialog(null)}
|
||||
onDownload={downloadDialog?.type === 'directory' ? handleDownloadDirectory : handleDownloadRepo}
|
||||
title={downloadDialog?.type === 'directory' ? 'Download Current Directory' : 'Download Repository'}
|
||||
description={downloadDialog?.type === 'directory'
|
||||
? 'This will create a ZIP archive of the current directory and all its contents.'
|
||||
: 'This will create a ZIP archive of the entire repository.'}
|
||||
itemName={downloadDialog?.type === 'directory' ? currentPath.split('/').pop() || 'Directory' : repoName || 'Repository'}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -22,7 +22,7 @@ interface FilePreviewProps {
|
||||
}
|
||||
|
||||
export const FilePreview = memo(function FilePreview({ file, hideHeader = false, isMobileModal = false, onCloseModal, onFileSaved, initialLineNumber }: FilePreviewProps) {
|
||||
const isMarkdownFile = file.name.endsWith('.md') || file.name.endsWith('.mdx') || file.mimeType === 'text/markdown'
|
||||
const isMarkdownFile = file.name.toLowerCase().endsWith('.md') || file.name.toLowerCase().endsWith('.mdx') || file.mimeType === 'text/markdown'
|
||||
|
||||
const [viewMode, setViewMode] = useState<'preview' | 'edit'>('preview')
|
||||
const [editContent, setEditContent] = useState('')
|
||||
@@ -33,6 +33,7 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
const [markdownPreview, setMarkdownPreview] = useState(isMarkdownFile)
|
||||
const [isLoadingAllContent, setIsLoadingAllContent] = useState(false)
|
||||
const [fullContentLoaded, setFullContentLoaded] = useState(false)
|
||||
const [fullContent, setFullContent] = useState<string | null>(null)
|
||||
const virtualizedRef = useRef<VirtualizedTextViewHandle>(null)
|
||||
const contentRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
@@ -41,18 +42,25 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
|
||||
useEffect(() => {
|
||||
setFullContentLoaded(false)
|
||||
}, [file.path])
|
||||
setMarkdownPreview(isMarkdownFile)
|
||||
setFullContent(null)
|
||||
}, [file.path, isMarkdownFile])
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldVirtualize && isMarkdownFile && markdownPreview && !isMarkdownTooLarge && !fullContentLoaded) {
|
||||
const loadContent = async () => {
|
||||
if (!virtualizedRef.current) return
|
||||
setIsLoadingAllContent(true)
|
||||
await virtualizedRef.current.loadAll()
|
||||
setFullContentLoaded(true)
|
||||
setIsLoadingAllContent(false)
|
||||
try {
|
||||
await virtualizedRef.current.loadAll()
|
||||
setFullContentLoaded(true)
|
||||
} catch {
|
||||
setFullContentLoaded(false)
|
||||
} finally {
|
||||
setIsLoadingAllContent(false)
|
||||
}
|
||||
}
|
||||
const timer = setTimeout(loadContent, 50)
|
||||
const timer = setTimeout(loadContent, 0)
|
||||
return () => clearTimeout(timer)
|
||||
}
|
||||
}, [shouldVirtualize, isMarkdownFile, markdownPreview, isMarkdownTooLarge, fullContentLoaded])
|
||||
@@ -191,7 +199,6 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
|
||||
if (shouldVirtualize && isTextFile) {
|
||||
const showMarkdownPreview = isMarkdownFile && markdownPreview && viewMode !== 'edit'
|
||||
const fullContent = virtualizedRef.current?.getFullContent()
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -203,6 +210,7 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
editable={viewMode === 'edit'}
|
||||
onSaveStateChange={handleVirtualizedSaveStateChange}
|
||||
onSave={handleVirtualizedSave}
|
||||
onContentLoaded={setFullContent}
|
||||
className="h-full"
|
||||
initialLineNumber={initialLineNumber}
|
||||
lineWrap={lineWrap}
|
||||
|
||||
@@ -76,6 +76,7 @@ export function FilePreviewDialog({ isOpen, onClose, filePath, repoBasePath, onF
|
||||
</div>
|
||||
) : file ? (
|
||||
<FilePreview
|
||||
key={file.path}
|
||||
file={file}
|
||||
hideHeader={false}
|
||||
isMobileModal={true}
|
||||
|
||||
@@ -56,6 +56,7 @@ export const MobileFilePreviewModal = memo(function MobileFilePreviewModal({
|
||||
<FullscreenSheet style={{ ...GPU_ACCELERATED_STYLE, ...swipeStyles }}>
|
||||
<div className={`h-full overflow-hidden bg-background pt-safe ${showFilePreviewHeader ? "" : "pb-8"}`}>
|
||||
<FilePreview
|
||||
key={localFile.path}
|
||||
file={localFile}
|
||||
hideHeader={!showFilePreviewHeader}
|
||||
isMobileModal={showFilePreviewHeader}
|
||||
|
||||
Reference in new issue
Block a user