From 8dbfc7cdfe310e0ad02f99a22bd6b536b08bb563 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Mon, 28 Sep 2026 22:51:31 -0400 Subject: [PATCH] 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. --- .../file-browser/FilePreview.test.tsx | 36 ++++++++++++++++++- .../components/file-browser/FilePreview.tsx | 31 +++++++++++++--- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/file-browser/FilePreview.test.tsx b/frontend/src/components/file-browser/FilePreview.test.tsx index bf3ae3dd..33cb5616 100644 --- a/frontend/src/components/file-browser/FilePreview.test.tsx +++ b/frontend/src/components/file-browser/FilePreview.test.tsx @@ -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() + + 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() + + 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() + + fireEvent.click(screen.getByTitle('Close preview')) + + expect(onCloseModal).toHaveBeenCalled() + }) + it('keeps the success and destructive tints on the edit actions in dark mode', () => { render() diff --git a/frontend/src/components/file-browser/FilePreview.tsx b/frontend/src/components/file-browser/FilePreview.tsx index fb91e1a5..b2404b17 100644 --- a/frontend/src/components/file-browser/FilePreview.tsx +++ b/frontend/src/components/file-browser/FilePreview.tsx @@ -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(null) const virtualizedRef = useRef(null) const contentRef = useRef(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 ( -
- {!hideHeader && ( +
+ {!hideHeader && !isDesktopFullscreen && ( <> -
+

{file.name} @@ -451,8 +454,14 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false, )} + {!isMobilePreview && !isFullscreen && viewMode !== 'edit' && ( + + )} + {viewMode !== 'edit' && isMobileModal && onCloseModal && ( - )} @@ -460,6 +469,18 @@ export const FilePreview = memo(function FilePreview({ file, hideHeader = false,

)} + + {isFullscreen && (isDesktopFullscreen || hideHeader) && ( + + )}