mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(files): add fullscreen preview with a minimal close control
Add a fullscreen toggle to the desktop file preview header. Fullscreen fills the viewport, hides the header, and shows only a small on-top X to exit. Keep the mobile preview fullscreen by default with its close button layered above the content, and give the headerless mobile preview the same small on-top X.
This commit is contained in:
1 parent
12eba5097c
commit
8dbfc7cdfe
2 files changed
+61
-6
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { FilePreview } from './FilePreview'
|
||||
import type { FileInfo } from '@/types/files'
|
||||
@@ -55,6 +55,40 @@ describe('FilePreview header buttons', () => {
|
||||
expect(screen.getByText('# heading')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('enters fullscreen from the header toggle and exits with the small close button', () => {
|
||||
render(<FilePreview file={textFile('Dockerfile', 'text/plain')} />)
|
||||
|
||||
expect(screen.queryByTitle('Exit fullscreen')).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByTitle('Enter fullscreen'))
|
||||
|
||||
expect(screen.queryByTitle('Enter fullscreen')).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByTitle('Exit fullscreen'))
|
||||
|
||||
expect(screen.getByTitle('Enter fullscreen')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('closes a mobile preview from the on-top close button without a fullscreen toggle', () => {
|
||||
const onCloseModal = vi.fn()
|
||||
render(<FilePreview file={textFile('Dockerfile', 'text/plain')} isMobileModal onCloseModal={onCloseModal} />)
|
||||
|
||||
expect(screen.queryByTitle('Enter fullscreen')).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByTitle('Close preview'))
|
||||
|
||||
expect(onCloseModal).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows an on-top close button for a headerless mobile preview', () => {
|
||||
const onCloseModal = vi.fn()
|
||||
render(<FilePreview file={textFile('Dockerfile', 'text/plain')} hideHeader onCloseModal={onCloseModal} />)
|
||||
|
||||
fireEvent.click(screen.getByTitle('Close preview'))
|
||||
|
||||
expect(onCloseModal).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps the success and destructive tints on the edit actions in dark mode', () => {
|
||||
render(<FilePreview file={textFile('Dockerfile', 'text/plain')} />)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useCallback, useRef, useEffect, memo } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Download, X, Edit3, Save, X as XIcon, WrapText, Eye, Code, ExternalLink } from 'lucide-react'
|
||||
import { Download, X, Edit3, Save, X as XIcon, WrapText, Eye, Code, ExternalLink, Maximize2 } from 'lucide-react'
|
||||
import type { FileInfo } from '@/types/files'
|
||||
import { getFileApiUrl } from '@/api/files'
|
||||
import { saveFileFromUrl } from '@/lib/download'
|
||||
@@ -41,6 +41,9 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
const [localMdContent, setLocalMdContent] = useState<string | null>(null)
|
||||
const virtualizedRef = useRef<VirtualizedTextViewHandle>(null)
|
||||
const contentRef = useRef<HTMLDivElement>(null)
|
||||
const isMobilePreview = isMobileModal || Boolean(onCloseModal)
|
||||
const [isFullscreen, setIsFullscreen] = useState(isMobilePreview)
|
||||
const isDesktopFullscreen = isFullscreen && !isMobilePreview
|
||||
|
||||
const shouldVirtualize = file.size > VIRTUALIZATION_THRESHOLD_BYTES && !file.mimeType?.startsWith('image/')
|
||||
const isMarkdownTooLarge = file.size > MARKDOWN_PREVIEW_SIZE_LIMIT
|
||||
@@ -373,10 +376,10 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
const showCancelButton = viewMode === 'edit'
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col bg-background">
|
||||
{!hideHeader && (
|
||||
<div className={`${isDesktopFullscreen ? 'fixed inset-0 z-50' : 'h-full'} relative flex flex-col bg-background`}>
|
||||
{!hideHeader && !isDesktopFullscreen && (
|
||||
<>
|
||||
<div className={`flex items-start gap-2 px-3 py-2 border-b border-border flex-shrink-0 overflow-hidden ${isMobileModal ? 'pt-3' : ''}`}>
|
||||
<div className={`relative z-10 flex items-start gap-2 px-3 py-2 border-b border-border flex-shrink-0 overflow-hidden ${isMobileModal ? 'pt-3' : ''}`}>
|
||||
<div className="flex-1 min-w-0 overflow-hidden">
|
||||
<h3 className="text-foreground text-sm font-medium break-all leading-tight">
|
||||
{file.name}
|
||||
@@ -451,8 +454,14 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{!isMobilePreview && !isFullscreen && viewMode !== 'edit' && (
|
||||
<Button variant="outline" size="sm" onClick={(e) => { e.stopPropagation(); e.preventDefault(); setIsFullscreen(true) }} className="h-7 w-7 p-0" title="Enter fullscreen">
|
||||
<Maximize2 className="w-3 h-3" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{viewMode !== 'edit' && isMobileModal && onCloseModal && (
|
||||
<Button variant="ghost" size="sm" onClick={(e) => { e.stopPropagation(); e.preventDefault(); onCloseModal() }} className={DESTRUCTIVE_TINT_BUTTON_CLASS}>
|
||||
<Button variant="ghost" size="sm" onClick={(e) => { e.stopPropagation(); e.preventDefault(); onCloseModal() }} className={DESTRUCTIVE_TINT_BUTTON_CLASS} title="Close preview">
|
||||
<X className="w-3 h-3" />
|
||||
</Button>
|
||||
)}
|
||||
@@ -460,6 +469,18 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isFullscreen && (isDesktopFullscreen || hideHeader) && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={(e) => { e.stopPropagation(); e.preventDefault(); if (isMobilePreview) { onCloseModal?.() } else { setIsFullscreen(false) } }}
|
||||
className="absolute top-2 right-2 z-[60] h-6 w-6 p-0 rounded-full bg-background/80 text-muted-foreground shadow-sm backdrop-blur-sm hover:bg-muted hover:text-foreground"
|
||||
title={isMobilePreview ? 'Close preview' : 'Exit fullscreen'}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<div
|
||||
ref={contentRef}
|
||||
|
||||
Reference in new issue
Block a user