diff --git a/src/components/Shakespeare/PreviewPane.tsx b/src/components/Shakespeare/PreviewPane.tsx index f9a434ad..ee669899 100644 --- a/src/components/Shakespeare/PreviewPane.tsx +++ b/src/components/Shakespeare/PreviewPane.tsx @@ -10,7 +10,7 @@ import { useBuildProject } from '@/hooks/useBuildProject'; import { Tabs, TabsContent } from '@/components/ui/tabs'; import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'; import { Button } from '@/components/ui/button'; -import { FolderOpen, ArrowLeft, Bug, Copy, Check, Play, Loader2, MenuIcon, Code, Rocket, X, Terminal } from 'lucide-react'; +import { FolderOpen, ArrowLeft, Bug, Copy, Check, Play, Loader2, MenuIcon, Code, Rocket, X, Terminal, Expand, Shrink } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; import { GitStatusIndicator } from '@/components/GitStatusIndicator'; import { BrowserAddressBar } from '@/components/ui/browser-address-bar'; @@ -89,6 +89,8 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o const [historyIndex, setHistoryIndex] = useState(0); const [deployDialogOpen, setDeployDialogOpen] = useState(false); + const [isFullscreen, setIsFullscreen] = useState(false); + const previewContainerRef = useRef(null); const iframeRef = useRef(null); const { fs } = useFS(); const { projectsPath } = useFSPaths(); @@ -291,33 +293,9 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o sendNavigationCommand('refresh'); }, [sendNavigationCommand]); - const goBackIframe = useCallback(() => { - if (historyIndex > 0) { - // Move back in history - const newIndex = historyIndex - 1; - const targetPath = navigationHistory[newIndex]; - - setHistoryIndex(newIndex); - setCurrentPath(targetPath); - - // Tell iframe to navigate to this path - sendNavigationCommand('navigate', { url: targetPath }); - } - }, [historyIndex, navigationHistory, sendNavigationCommand]); - - const goForwardIframe = useCallback(() => { - if (historyIndex < navigationHistory.length - 1) { - // Move forward in history - const newIndex = historyIndex + 1; - const targetPath = navigationHistory[newIndex]; - - setHistoryIndex(newIndex); - setCurrentPath(targetPath); - - // Tell iframe to navigate to this path - sendNavigationCommand('navigate', { url: targetPath }); - } - }, [historyIndex, navigationHistory, sendNavigationCommand]); + const toggleFullscreen = useCallback(() => { + setIsFullscreen(prev => !prev); + }, []); const handleFetch = useCallback(async (request: JSONRPCRequest) => { const { params, id } = request; @@ -563,7 +541,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o @@ -643,7 +621,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o Open menu - + {isPreviewable && ( -
+
{/* Always show browser address bar */}
0} - canGoForward={hasBuiltProject && historyIndex < navigationHistory.length - 1} + navigationHistory={navigationHistory} + leftContent={( + + )} extraContent={(
{(!isMobile && onToggleView && isPreviewable) && ( diff --git a/src/components/ui/browser-address-bar.test.tsx b/src/components/ui/browser-address-bar.test.tsx index 53505fcb..68ac8ab9 100644 --- a/src/components/ui/browser-address-bar.test.tsx +++ b/src/components/ui/browser-address-bar.test.tsx @@ -3,11 +3,9 @@ import { render, screen, fireEvent } from '@testing-library/react'; import { BrowserAddressBar } from './browser-address-bar'; describe('BrowserAddressBar', () => { - it('renders navigation buttons and address input', () => { - render(); + it('renders address input and refresh button', () => { + render(); - expect(screen.getByTitle('Go back')).toBeInTheDocument(); - expect(screen.getByTitle('Go forward')).toBeInTheDocument(); expect(screen.getByTitle('Refresh')).toBeInTheDocument(); expect(screen.getByPlaceholderText('Enter path (e.g., /, /about)')).toBeInTheDocument(); }); @@ -23,65 +21,30 @@ describe('BrowserAddressBar', () => { expect(onNavigate).toHaveBeenCalledWith('/about'); }); - it('disables back/forward buttons based on canGoBack/canGoForward props and handlers', () => { - // Test with handlers provided - const onBack = vi.fn(); - const onForward = vi.fn(); + it('disables input when no onNavigate handler is provided', () => { + render(); - render( - - ); - - expect(screen.getByTitle('Go back')).toBeDisabled(); // disabled because canGoBack=false - expect(screen.getByTitle('Go forward')).not.toBeDisabled(); // enabled because canGoForward=true and handler provided - }); - - it('disables buttons when no handlers are provided', () => { - render( - - ); - - // All buttons should be disabled when no handlers are provided - expect(screen.getByTitle('Go back')).toBeDisabled(); - expect(screen.getByTitle('Go forward')).toBeDisabled(); - expect(screen.getByTitle('Refresh')).toBeDisabled(); - - // Input should also be disabled when no onNavigate handler is provided + // Input should be disabled when no onNavigate handler is provided expect(screen.getByPlaceholderText('Enter path (e.g., /, /about)')).toBeDisabled(); }); - it('calls navigation handlers when buttons are clicked', () => { - const onBack = vi.fn(); - const onForward = vi.fn(); + it('shows refresh button inside input when onRefresh handler is provided', () => { const onRefresh = vi.fn(); + render(); - render( - - ); + const refreshButton = screen.getByTitle('Refresh'); + expect(refreshButton).toBeInTheDocument(); - fireEvent.click(screen.getByTitle('Go back')); - fireEvent.click(screen.getByTitle('Go forward')); - fireEvent.click(screen.getByTitle('Refresh')); - - expect(onBack).toHaveBeenCalled(); - expect(onForward).toHaveBeenCalled(); + fireEvent.click(refreshButton); expect(onRefresh).toHaveBeenCalled(); }); + it('does not show refresh button when no onRefresh handler is provided', () => { + render(); + + expect(screen.queryByTitle('Refresh')).not.toBeInTheDocument(); + }); + it('updates input value when currentPath prop changes', () => { const { rerender } = render(); @@ -98,4 +61,100 @@ describe('BrowserAddressBar', () => { expect(input).toHaveValue('/contact'); }); + + it('renders leftContent when provided', () => { + render( + Left} + /> + ); + + expect(screen.getByTestId('left-button')).toBeInTheDocument(); + }); + + it('renders extraContent when provided', () => { + render( + Extra} + /> + ); + + expect(screen.getByTestId('extra-button')).toBeInTheDocument(); + }); + + it('shows navigation history dropdown when input is focused', () => { + const navigationHistory = ['/', '/about', '/contact']; + render( + + ); + + const input = screen.getByPlaceholderText('Enter path (e.g., /, /about)'); + fireEvent.focus(input); + + // History should be shown in reverse order (most recent first) + expect(screen.getByText('/contact')).toBeInTheDocument(); + expect(screen.getByText('/about')).toBeInTheDocument(); + expect(screen.getByText('/')).toBeInTheDocument(); + }); + + it('does not show history dropdown when navigationHistory is empty', () => { + render( + + ); + + const input = screen.getByPlaceholderText('Enter path (e.g., /, /about)'); + fireEvent.focus(input); + + // No history items should be visible + expect(screen.queryByRole('button', { name: /\// })).not.toBeInTheDocument(); + }); + + it('navigates when clicking a history item', () => { + const onNavigate = vi.fn(); + const navigationHistory = ['/', '/about', '/contact']; + render( + + ); + + const input = screen.getByPlaceholderText('Enter path (e.g., /, /about)'); + fireEvent.focus(input); + + const aboutButton = screen.getByText('/about'); + fireEvent.click(aboutButton); + + expect(onNavigate).toHaveBeenCalledWith('/about'); + }); + + it('removes duplicate paths from history', () => { + const navigationHistory = ['/', '/about', '/', '/contact', '/about']; + render( + + ); + + const input = screen.getByPlaceholderText('Enter path (e.g., /, /about)'); + fireEvent.focus(input); + + // Should only show unique paths + const allButtons = screen.getAllByRole('button'); + // Filter out the refresh button if present, only count history items + const historyButtons = allButtons.filter(btn => + btn.textContent === '/' || + btn.textContent === '/about' || + btn.textContent === '/contact' + ); + + expect(historyButtons).toHaveLength(3); + }); }); \ No newline at end of file diff --git a/src/components/ui/browser-address-bar.tsx b/src/components/ui/browser-address-bar.tsx index 64b207a9..809a3bfd 100644 --- a/src/components/ui/browser-address-bar.tsx +++ b/src/components/ui/browser-address-bar.tsx @@ -1,7 +1,7 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useRef, useMemo } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; -import { ChevronLeft, ChevronRight, RefreshCw } from 'lucide-react'; +import { CheckIcon, RefreshCw } from 'lucide-react'; import { cn } from '@/lib/utils'; import { ReactNode } from 'react'; @@ -9,32 +9,47 @@ interface BrowserAddressBarProps { currentPath?: string; onNavigate?: (path: string) => void; onRefresh?: () => void; - onBack?: () => void; - onForward?: () => void; - canGoBack?: boolean; - canGoForward?: boolean; className?: string; extraContent?: ReactNode; + leftContent?: ReactNode; + navigationHistory?: string[]; } export function BrowserAddressBar({ currentPath = '/', onNavigate, onRefresh, - onBack, - onForward, - canGoBack = false, - canGoForward = false, className, extraContent, + leftContent, + navigationHistory = [], }: BrowserAddressBarProps) { const [inputValue, setInputValue] = useState(currentPath); + const [showHistory, setShowHistory] = useState(false); + const inputRef = useRef(null); + const dropdownRef = useRef(null); // Update input value when currentPath changes (e.g., when iframe navigates) useEffect(() => { setInputValue(currentPath); }, [currentPath]); + // Close dropdown when clicking outside + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + const target = event.target as Node | null; + const dropdownElement = dropdownRef.current; + const inputElement = inputRef.current; + + if (target && !dropdownElement?.contains(target) && !inputElement?.contains(target)) { + setShowHistory(false); + } + }; + + document.addEventListener('mousedown', handleClickOutside); + return () => document.removeEventListener('mousedown', handleClickOutside); + }, []); + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!onNavigate) return; @@ -47,61 +62,91 @@ export function BrowserAddressBar({ } onNavigate(path); + setShowHistory(false); }; const handleInputChange = (e: React.ChangeEvent) => { setInputValue(e.target.value); }; + const handleInputFocus = () => { + if (navigationHistory.length > 0) { + setShowHistory(true); + } + }; + + const handleHistoryItemClick = (path: string) => { + if (onNavigate) { + onNavigate(path); + setShowHistory(false); + inputRef.current?.blur(); + } + }; + + // Get unique history items (reverse to show most recent first, remove duplicates) + const uniqueHistory = useMemo(() => Array.from(new Set([...navigationHistory].reverse())), [navigationHistory]); + return (
- {/* Navigation buttons */} -
- - - -
+ {/* Left content (e.g., maximize button) */} + {leftContent} - {/* Address bar */} -
- + {/* Address bar with refresh button inside */} + +
+ + {onRefresh && ( + + )} + + {/* Navigation history dropdown */} + {showHistory && uniqueHistory.length > 0 && ( +
+ {uniqueHistory.map((path, index) => ( + + ))} +
+ )} +
{/* Extra content */} diff --git a/src/components/ui/button-variants.ts b/src/components/ui/button-variants.ts index 102facd2..0cd815e6 100644 --- a/src/components/ui/button-variants.ts +++ b/src/components/ui/button-variants.ts @@ -1,7 +1,7 @@ import { cva } from "class-variance-authority" export const buttonVariants = cva( - "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", + "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0", { variants: { variant: { diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index 3abc4939..142e8330 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -335,7 +335,7 @@ export function ProjectView() {
{/* Chat Panel */} - +
{/* Chat Header */}
@@ -429,7 +429,7 @@ export function ProjectView() { {/* Preview/Code Panel */} - +
{project ? (