Files
opencode-manager/frontend/src/components/file-browser/MobileFilePreviewModal.tsx
T
Chris Scott da6cad8b3a 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
2026-01-26 23:09:27 -05:00

70 lines
2.0 KiB
TypeScript

import { memo, useCallback, useState, useEffect, useRef } from "react";
import { FilePreview } from "./FilePreview";
import { FullscreenSheet } from "@/components/ui/fullscreen-sheet";
import type { FileInfo } from "@/types/files";
import { GPU_ACCELERATED_STYLE, MODAL_TRANSITION_MS } from "@/lib/utils";
import { useSwipeBack } from "@/hooks/useMobile";
interface MobileFilePreviewModalProps {
isOpen: boolean;
onClose: () => void;
file: FileInfo | null;
showFilePreviewHeader?: boolean;
}
export const MobileFilePreviewModal = memo(function MobileFilePreviewModal({
isOpen,
onClose,
file,
showFilePreviewHeader = false,
}: MobileFilePreviewModalProps) {
const [localFile, setLocalFile] = useState<FileInfo | null>(null);
const isClosingRef = useRef(false);
const containerRef = useRef<HTMLDivElement>(null);
const { bind, swipeStyles } = useSwipeBack(onClose, {
enabled: isOpen,
});
useEffect(() => {
return bind(containerRef.current);
}, [bind]);
useEffect(() => {
if (isOpen && file && !file.isDirectory) {
setLocalFile(file);
isClosingRef.current = false;
}
}, [isOpen, file]);
const handleClose = useCallback(() => {
if (isClosingRef.current) return;
isClosingRef.current = true;
onClose();
setTimeout(() => {
setLocalFile(null);
isClosingRef.current = false;
}, MODAL_TRANSITION_MS);
}, [onClose]);
if (!isOpen || !localFile) {
return null;
}
return (
<div ref={containerRef} style={{ isolation: 'isolate' }}>
<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}
onCloseModal={handleClose}
/>
</div>
</FullscreenSheet>
</div>
);
})